├── doc ├── ref │ └── .gitignore ├── hid1_11.pdf ├── USBKeyScan.pdf ├── Contribute.md ├── Keymap.md └── GettingStarted.md ├── lib ├── cortexM │ ├── PSR.h │ ├── switch.h │ ├── armcpu.c │ ├── armcpu.h │ ├── switch.c │ ├── core_cmFunc.h │ └── core_cmInstr.h ├── stdlib.h ├── stdio.h ├── stdlib.c └── stdio.c ├── tool └── keymapeditor │ ├── firmware.js │ └── keyboard.css ├── hal ├── blackpill │ ├── drivers │ │ ├── stm32f1xx.h │ │ ├── stm32f103xb.h │ │ ├── stm32f1xx_it.h │ │ ├── system_stm32f1xx.h │ │ ├── stm32f1xx_hal_pcd_ex.h │ │ ├── stm32f1xx_hal_gpio_ex.c │ │ ├── stm32f1xx_it.c │ │ └── stm32f1xx_hal_msp.c │ ├── Gpio.c │ ├── Timer.c │ ├── MemoryMap.h │ ├── Interrupt.c │ └── Uart.c ├── HalGpio.h ├── HalTimer.h ├── HalUart.h └── HalInterrupt.h ├── blackpill.sh ├── blackpill_loader.sh ├── .settings ├── org.eclipse.cdt.core.prefs └── language.settings.xml ├── include ├── memio.h ├── stdarg.h └── stdbool.h ├── app ├── blackpill │ ├── Flash.h │ ├── Layout │ │ ├── gosupeek │ │ │ ├── Layout.h │ │ │ └── Layout.c │ │ └── cambrian │ │ │ ├── Layout.h │ │ │ └── Layout.c │ ├── KeyHw.h │ ├── Flash.c │ ├── keymap.h │ ├── MSC │ │ ├── usbd_msc_data.h │ │ ├── usbd_msc_data.c │ │ ├── usbd_msc_desc.h │ │ ├── usb_msc_device.h │ │ ├── usbd_storage_if.h │ │ ├── usb_msc_device.c │ │ ├── usbd_msc.h │ │ ├── usbd_msc_bot.h │ │ └── usbd_msc_scsi.h │ ├── HID │ │ ├── usbd_hid_desc.h │ │ ├── usb_hid_keyboard.h │ │ ├── usbd_hid.h │ │ └── usb_hid_keyboard.c │ ├── USB │ │ ├── usbd_ctlreq.h │ │ ├── usbd_ioreq.h │ │ ├── usbd_core.h │ │ ├── usbd_conf.h │ │ └── usbd_ioreq.c │ ├── KeyHw.c │ └── Keycode.h ├── HostCommTask.c ├── PollingTask.c └── DebugCliTask.c ├── kernel ├── synch.h ├── event.c ├── task.h ├── msg.h ├── Kernel.h ├── synch.c ├── msg.c ├── event.h ├── task.c └── Kernel.c ├── .gitignore ├── .project ├── LICENSE ├── README.md ├── boot └── blackpill │ └── main.c └── .cproject /doc/ref/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | -------------------------------------------------------------------------------- /lib/cortexM/PSR.h: -------------------------------------------------------------------------------- 1 | #define PSR_INIT 0x21000000 2 | -------------------------------------------------------------------------------- /doc/hid1_11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navilera/Gosu/HEAD/doc/hid1_11.pdf -------------------------------------------------------------------------------- /doc/USBKeyScan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navilera/Gosu/HEAD/doc/USBKeyScan.pdf -------------------------------------------------------------------------------- /tool/keymapeditor/firmware.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navilera/Gosu/HEAD/tool/keymapeditor/firmware.js -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f1xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navilera/Gosu/HEAD/hal/blackpill/drivers/stm32f1xx.h -------------------------------------------------------------------------------- /blackpill.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make -f build/blackpill/Makefile clean 4 | make -f build/blackpill/Makefile $1 $2 5 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f103xb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navilera/Gosu/HEAD/hal/blackpill/drivers/stm32f103xb.h -------------------------------------------------------------------------------- /blackpill_loader.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z $1 ] 4 | then 5 | ./blackpill.sh clean 6 | fi 7 | 8 | ./blackpill.sh LOADER=1 $1 9 | -------------------------------------------------------------------------------- /hal/HalGpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HalGpio.h 3 | * 4 | * Created on: Jan 31, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef HAL_HALGPIO_H_ 9 | #define HAL_HALGPIO_H_ 10 | 11 | void Hal_gpio_init(void); 12 | 13 | #endif /* HAL_HALGPIO_H_ */ 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1032495071/append=true 3 | environment/project/cdt.managedbuild.toolchain.gnu.cross.base.1032495071/appendContributed=true 4 | -------------------------------------------------------------------------------- /include/memio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * memio.h 3 | * 4 | * Created on: Sep 21, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef INCLUDE_MEMIO_H_ 9 | #define INCLUDE_MEMIO_H_ 10 | 11 | #define SET_BIT(p,n) ((p) |= (1 << (n))) 12 | #define CLR_BIT(p,n) ((p) &= ~(1 << (n))) 13 | 14 | #endif /* INCLUDE_MEMIO_H_ */ 15 | -------------------------------------------------------------------------------- /hal/HalTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HalTimer.h 3 | * 4 | * Created on: Sep 27, 2018 5 | * Author: yiman 6 | */ 7 | 8 | #ifndef HAL_HALTIMER_H_ 9 | #define HAL_HALTIMER_H_ 10 | 11 | void Hal_timer_init(void); 12 | uint32_t Hal_timer_get_1ms_counter(void); 13 | 14 | 15 | #endif /* HAL_HALTIMER_H_ */ 16 | -------------------------------------------------------------------------------- /hal/HalUart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HalUart.h 3 | * 4 | * Created on: Sep 8, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef HAL_HALUART_H_ 9 | #define HAL_HALUART_H_ 10 | 11 | void Hal_uart_init(void); 12 | void Hal_uart_put_char(uint8_t ch); 13 | uint8_t Hal_uart_get_char(void); 14 | 15 | #endif /* HAL_HALUART_H_ */ 16 | -------------------------------------------------------------------------------- /app/blackpill/Flash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Flash.h 3 | * 4 | * Created on: Mar 9, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef APP_BLUEPILL_FLASH_H_ 9 | #define APP_BLUEPILL_FLASH_H_ 10 | 11 | #include "stdint.h" 12 | 13 | void Flash_write_page(uint8_t* pageBuffer, uint32_t PageAddress); 14 | #endif /* APP_BLUEPILL_FLASH_H_ */ 15 | -------------------------------------------------------------------------------- /lib/cortexM/switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * switch.h 3 | * 4 | * Created on: Jan 29, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef LIB_CORTEXM_SWITCH_H_ 9 | #define LIB_CORTEXM_SWITCH_H_ 10 | 11 | void Arch_start(void); 12 | void Arch_context_switching(void); 13 | void Arch_Restore_context(void); 14 | 15 | #endif /* LIB_CORTEXM_SWITCH_H_ */ 16 | -------------------------------------------------------------------------------- /hal/blackpill/Gpio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Gpio.c 3 | * 4 | * Created on: Jan 31, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #include "stm32f1xx_hal.h" 9 | #include "HalGpio.h" 10 | 11 | void Hal_gpio_init(void) 12 | { 13 | /* GPIO Ports Clock Enable */ 14 | __HAL_RCC_GPIOA_CLK_ENABLE(); 15 | __HAL_RCC_GPIOB_CLK_ENABLE(); 16 | __HAL_RCC_GPIOC_CLK_ENABLE(); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /lib/cortexM/armcpu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * armcpu.c 3 | * 4 | * Created on: Sep 22, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "armcpu.h" 9 | 10 | void enable_irq(void) 11 | { 12 | __asm__ ("cpsie i"); 13 | } 14 | 15 | void enable_fiq(void) 16 | { 17 | 18 | } 19 | 20 | void disable_irq(void) 21 | { 22 | __asm__ ("cpsid i"); 23 | } 24 | 25 | void disable_fiq(void) 26 | { 27 | 28 | } 29 | 30 | -------------------------------------------------------------------------------- /include/stdarg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stdarg.h 3 | * 4 | * Created on: Sep 19, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef INCLUDE_STDARG_H_ 9 | #define INCLUDE_STDARG_H_ 10 | 11 | typedef __builtin_va_list va_list; 12 | 13 | #define va_start(v,l) __builtin_va_start(v,l) 14 | #define va_end(v) __builtin_va_end(v) 15 | #define va_arg(v,l) __builtin_va_arg(v,l) 16 | 17 | #endif /* INCLUDE_STDARG_H_ */ 18 | -------------------------------------------------------------------------------- /hal/blackpill/Timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer.c 3 | * 4 | * Created on: Sep 27, 2018 5 | * Author: yiman 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdio.h" 10 | 11 | #include "HalTimer.h" 12 | 13 | 14 | static uint32_t sInternal_1ms_counter; 15 | 16 | void Hal_timer_init(void) 17 | { 18 | } 19 | 20 | uint32_t Hal_timer_get_1ms_counter(void) 21 | { 22 | return sInternal_1ms_counter; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /doc/Contribute.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | To participate in the project, you just need to fork, hack, commit, push to your 4 | github repo (forked), and create pull request. Code shouldn't contain 5 | copyrighted code unless it has Apache license. 6 | 7 | You shall try to code based on [LLVM Coding Standards][]. It is recommend to use 8 | [clang-format][] for newly created code. 9 | 10 | [LLVM Coding Standards]: https://llvm.org/docs/CodingStandards.html 11 | [clang-format]: https://clang.llvm.org/docs/ClangFormat.html 12 | -------------------------------------------------------------------------------- /lib/cortexM/armcpu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * armcpu.h 3 | * 4 | * Created on: Sep 22, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef LIB_ARMCPU_H_ 9 | #define LIB_ARMCPU_H_ 10 | 11 | #include "stdint.h" 12 | 13 | #define __CLZ __builtin_clz 14 | 15 | void enable_irq(void); 16 | void enable_fiq(void); 17 | void disable_irq(void); 18 | void disable_fiq(void); 19 | 20 | __inline void set_CONTROL(uint32_t control) 21 | { 22 | __asm__ ("MSR control, %0" : : "r" (control) : "memory"); 23 | } 24 | 25 | #endif /* LIB_ARMCPU_H_ */ 26 | -------------------------------------------------------------------------------- /kernel/synch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * synch.h 3 | * 4 | * Created on: Nov 8, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef KERNEL_SYNCH_H_ 9 | #define KERNEL_SYNCH_H_ 10 | 11 | typedef struct KernelMutext_t 12 | { 13 | uint32_t owner; 14 | bool lock; 15 | } KernelMutext_t; 16 | 17 | void Kernel_sem_init(int32_t max); 18 | bool Kernel_sem_test(void); 19 | void Kernel_sem_release(void); 20 | 21 | void Kernel_mutex_init(void); 22 | bool Kernel_mutex_lock(uint32_t owner); 23 | bool Kernel_mutex_unlock(uint32_t owner); 24 | 25 | #endif /* KERNEL_SYNCH_H_ */ 26 | -------------------------------------------------------------------------------- /app/blackpill/Layout/gosupeek/Layout.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_GOSUPEEK_LAYOUT 2 | #define APP_GOSUPEEK_LAYOUT 3 | 4 | #include "Keycode.h" 5 | 6 | #define NUM_LAYERS 2 7 | 8 | #define KEYMAP_COL_NUM 14 9 | #define KEYMAP_ROW_NUM 6 10 | #define TOTAL_KEY_MAP_SIZE (KEYMAP_COL_NUM * KEYMAP_ROW_NUM) 11 | 12 | extern Keypin_t gRowPin[KEYMAP_ROW_NUM]; 13 | extern Keypin_t gColPin[KEYMAP_COL_NUM]; 14 | extern uint8_t gKeymap_buffer_layer0[KEYMAP_ROW_NUM][KEYMAP_COL_NUM]; 15 | extern uint8_t gKeymap_buffer_layer1[KEYMAP_ROW_NUM][KEYMAP_COL_NUM]; 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /app/blackpill/KeyHw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * KeyHw.h 3 | * 4 | * Created on: Feb 11, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef APP_KEYHW_H_ 9 | #define APP_KEYHW_H_ 10 | 11 | #include "stdbool.h" 12 | #include "stdint.h" 13 | 14 | typedef struct KeyHwAddr 15 | { 16 | uint8_t col; 17 | uint8_t row; 18 | } KeyHwAddr_t; 19 | 20 | typedef struct Keypin 21 | { 22 | uint32_t port; 23 | uint32_t num; 24 | } Keypin_t; 25 | 26 | uint32_t KeyHw_polling(KeyHwAddr_t* keyHwAddrBuff, uint32_t max_count); 27 | bool KeyHw_IsPressed(uint32_t col, uint32_t row); 28 | 29 | #endif /* APP_KEYHW_H_ */ 30 | -------------------------------------------------------------------------------- /hal/HalInterrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HalInterrupt.h 3 | * 4 | * Created on: Sep 21, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef HAL_HALINTERRUPT_H_ 9 | #define HAL_HALINTERRUPT_H_ 10 | 11 | #define INTERRUPT_HANDLER_NUM 255 12 | 13 | typedef void (*InterHdlr_fptr)(void); 14 | 15 | void Hal_interrupt_init(void); 16 | void Hal_interrupt_enable(uint32_t interrupt_num); 17 | void Hal_interrupt_disable(uint32_t interrupt_num); 18 | void Hal_interrupt_register_handler(InterHdlr_fptr handler, uint32_t interrupt_num); 19 | void Hal_interrupt_run_handler(void); 20 | 21 | #endif /* HAL_HALINTERRUPT_H_ */ 22 | -------------------------------------------------------------------------------- /app/blackpill/Layout/cambrian/Layout.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_GOSUPEEK_LAYOUT 2 | #define APP_GOSUPEEK_LAYOUT 3 | 4 | #include "stdint.h" 5 | #include "Keycode.h" 6 | 7 | #define NUM_LAYERS 2 8 | 9 | #define KEYMAP_COL_NUM 15 10 | #define KEYMAP_ROW_NUM 5 11 | #define TOTAL_KEY_MAP_SIZE (KEYMAP_COL_NUM * KEYMAP_ROW_NUM) 12 | 13 | extern Keypin_t gRowPin[KEYMAP_ROW_NUM]; 14 | extern Keypin_t gColPin[KEYMAP_COL_NUM]; 15 | extern uint8_t gKeymap_buffer_layer0[KEYMAP_ROW_NUM][KEYMAP_COL_NUM]; 16 | extern uint8_t gKeymap_buffer_layer1[KEYMAP_ROW_NUM][KEYMAP_COL_NUM]; 17 | 18 | void ChangeReportByLayout(uint8_t *report); 19 | 20 | #endif 21 | 22 | -------------------------------------------------------------------------------- /lib/stdlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stdlib.h 3 | * 4 | * Created on: Sep 27, 2018 5 | * Author: yiman 6 | */ 7 | 8 | #ifndef LIB_STDLIB_H_ 9 | #define LIB_STDLIB_H_ 10 | 11 | #include "stdint.h" 12 | #include "stdbool.h" 13 | 14 | void delay(uint32_t ms); 15 | void memclr(void* dst, uint32_t count); 16 | uint32_t memfind(uint8_t* src, uint8_t byte, uint32_t count); 17 | bool memncmp(uint8_t* m1, uint8_t* m2, uint32_t count); 18 | void memncpy(uint8_t* dst, uint8_t* src, uint32_t count); 19 | uint32_t htou(char* ascii, uint32_t count); 20 | uint32_t strncnt(char* str, uint32_t max_len); 21 | 22 | void halt(char* filename, uint32_t line); 23 | 24 | #define HALT() halt(__FILE__, __LINE__); 25 | 26 | #endif /* LIB_STDLIB_H_ */ 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | *.bin 39 | 40 | # Debug files 41 | *.dSYM/ 42 | *.su 43 | *.idb 44 | *.pdb 45 | default.profraw 46 | 47 | # Kernel Module Compile Results 48 | *.mod* 49 | *.cmd 50 | .tmp_versions/ 51 | modules.order 52 | Module.symvers 53 | Mkfile.old 54 | dkms.conf 55 | *.swp 56 | /out/ 57 | 58 | # Accessaries 59 | tags 60 | 61 | -------------------------------------------------------------------------------- /kernel/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * event.c 3 | * 4 | * Created on: Nov 2, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | 11 | #include "event.h" 12 | 13 | static uint32_t sEventFlag; 14 | 15 | void Kernel_event_flag_init(void) 16 | { 17 | sEventFlag = 0; 18 | } 19 | 20 | void Kernel_event_flag_set(KernelEventFlag_t event) 21 | { 22 | sEventFlag |= (uint32_t)event; 23 | } 24 | 25 | void Kernel_event_flag_clear(KernelEventFlag_t event) 26 | { 27 | sEventFlag &= ~((uint32_t)event); 28 | } 29 | 30 | bool Kernel_event_flag_check(KernelEventFlag_t event) 31 | { 32 | if (sEventFlag & (uint32_t)event) 33 | { 34 | Kernel_event_flag_clear(event); 35 | return true; 36 | } 37 | return false; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /lib/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stdio.h 3 | * 4 | * Created on: Sep 17, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef LIB_STDIO_H_ 9 | #define LIB_STDIO_H_ 10 | 11 | #include "stdint.h" 12 | #include "stdarg.h" 13 | 14 | #if (DEBUG_PRINT == 1) 15 | #define DBG_PRINT(...) debug_printf(__VA_ARGS__) 16 | #else 17 | void dummy_print(const char* format, ...); 18 | #define DBG_PRINT(...) dummy_print(__VA_ARGS__) 19 | #endif 20 | 21 | typedef enum utoa_t 22 | { 23 | utoa_dec = 10, 24 | utoa_hex = 16, 25 | } utoa_t; 26 | 27 | uint32_t putstr(const char* s); 28 | uint32_t debug_printf(const char* format, ...); 29 | uint32_t vsprintf(char* buf, const char* format, va_list arg); 30 | uint32_t utoa(char* buf, uint32_t val, utoa_t base); 31 | 32 | #endif /* LIB_STDIO_H_ */ 33 | -------------------------------------------------------------------------------- /kernel/task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * task.h 3 | * 4 | * Created on: Oct 22, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef KERNEL_TASK_H_ 9 | #define KERNEL_TASK_H_ 10 | 11 | #define NOT_ENOUGH_TASK_NUM 0xFFFFFFFF 12 | 13 | typedef struct KernelTaskContext_t 14 | { 15 | uint32_t spsr; 16 | uint32_t r0_r12[13]; 17 | uint32_t pc; 18 | } KernelTaskContext_t; 19 | 20 | typedef struct KernelTcb_t 21 | { 22 | uint32_t sp; 23 | uint8_t* stack_base; 24 | } KernelTcb_t; 25 | 26 | typedef void (*KernelTaskFunc_t)(void); 27 | 28 | void Kernel_task_init(void); 29 | void Kernel_task_start(void); 30 | uint32_t Kernel_task_create(KernelTaskFunc_t startFunc); 31 | void Kernel_task_scheduler(void); 32 | uint32_t Kernel_task_get_current_task_id(void); 33 | 34 | #endif /* KERNEL_TASK_H_ */ 35 | -------------------------------------------------------------------------------- /app/blackpill/Flash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Flash.c 3 | * 4 | * Created on: Mar 9, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "MemoryMap.h" 10 | 11 | #include "stm32f1xx_hal_flash.h" 12 | 13 | extern void FLASH_PageErase(uint32_t PageAddress); 14 | extern HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data); 15 | 16 | void Flash_write_page(uint8_t* pageBuffer, uint32_t PageAddress) 17 | { 18 | uint32_t len = EFLASH_PAGESIZE / 4; 19 | uint32_t addr = EFLASH_BADDR(PageAddress); 20 | 21 | HAL_FLASH_Unlock(); 22 | 23 | FLASH_PageErase(addr); 24 | 25 | uint32_t* pData = (uint32_t*)pageBuffer; 26 | 27 | while(len--) 28 | { 29 | HAL_FLASH_Program(2, addr, *pData++); 30 | addr += 4; 31 | } 32 | 33 | HAL_FLASH_Lock(); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /kernel/msg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * message.h 3 | * 4 | * Created on: Nov 6, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef KERNEL_MSG_H_ 9 | #define KERNEL_MSG_H_ 10 | 11 | #define MSG_Q_SIZE_BYTE 512 12 | 13 | typedef enum KernelMsgQ_t 14 | { 15 | KernelMsgQ_D2hData, 16 | KernelMsgQ_DebugCmd, 17 | KernelMsgQ_Task2, 18 | 19 | KernelMsgQ_Num 20 | } KernelMsgQ_t; 21 | 22 | typedef struct KernelCirQ_t 23 | { 24 | uint32_t front; 25 | uint32_t rear; 26 | uint8_t Queue[MSG_Q_SIZE_BYTE]; 27 | } KernelCirQ_t; 28 | 29 | void Kernel_msgQ_init(void); 30 | bool Kernel_msgQ_is_empty(KernelMsgQ_t Qname); 31 | bool Kernel_msgQ_is_full(KernelMsgQ_t Qname); 32 | bool Kernel_msgQ_enqueue(KernelMsgQ_t Qname, uint8_t data); 33 | bool Kernel_msgQ_dequeue(KernelMsgQ_t Qname, uint8_t* out_data); 34 | 35 | #endif /* KERNEL_MSG_H_ */ 36 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Gosu 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /kernel/Kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Kernel.h 3 | * 4 | * Created on: Oct 28, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef KERNEL_KERNEL_H_ 9 | #define KERNEL_KERNEL_H_ 10 | 11 | #include "stdint.h" 12 | #include "stdbool.h" 13 | #include "task.h" 14 | #include "event.h" 15 | #include "msg.h" 16 | #include "synch.h" 17 | 18 | void Kernel_start(void); 19 | void Kernel_yield(void); 20 | void Kernel_send_events(uint32_t event_list); 21 | KernelEventFlag_t Kernel_wait_events(uint32_t waiting_list); 22 | bool Kernel_send_msg(KernelMsgQ_t Qname, void* data, uint32_t count); 23 | uint32_t Kernel_recv_msg(KernelMsgQ_t Qname, void* out_data, uint32_t count); 24 | void Kernel_flush_msg(KernelMsgQ_t Qname); 25 | void Kernel_lock_sem(void); 26 | void Kernel_unlock_sem(void); 27 | void Kernel_lock_mutex(void); 28 | void Kernel_unlock_mutex(void); 29 | 30 | #endif /* KERNEL_KERNEL_H_ */ 31 | -------------------------------------------------------------------------------- /app/blackpill/keymap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * file: keymap.h 3 | * auther: @eunchan 4 | * 5 | * description: Keymap Structure used in HID, KeymapDl 6 | * 7 | * © COPYRIGHT(c) 2019 Polypeak LLC, 8 | */ 9 | 10 | #ifndef APP_CORE_KEYMAP_H_ 11 | #define APP_CORE_KEYMAP_H_ 12 | 13 | #include "stdint.h" 14 | #include "stdbool.h" 15 | 16 | #include "KeyHw.h" 17 | 18 | #define KEYMAP_MAGIC_H_WORD 0xC0FFEED0 19 | #define KEYMAP_MAGIC_L_WORD 0xBEEFC0DE 20 | 21 | #define HID_MODIKEY_IDX 0 22 | #define HID_KEY_START_IDX 2 23 | #define HID_KBD_REPORT_BYTE 8 24 | #define HID_MAX_MULTIPLE_INPUT 7 // 1 modi key + 6 char key 25 | 26 | /* 27 | * public functions 28 | */ 29 | void LoadKeymap(void); 30 | bool VerifyKeyMapFile(uint8_t* keyfile); 31 | bool WriteKeyMapToFlash(uint8_t* keyfile, uint32_t size); 32 | 33 | bool KeyMap_checkFnKey(KeyHwAddr_t* hwPollingAddrs, uint32_t pollingCount); 34 | void KeyMap_getReport(bool isPressedFnKey, uint8_t* hidKeyboardReport, KeyHwAddr_t* hwPollingAddrs, uint32_t pollingCount); 35 | 36 | #endif /*APP_CORE_KEYMAP_H_*/ 37 | -------------------------------------------------------------------------------- /hal/blackpill/MemoryMap.h: -------------------------------------------------------------------------------- 1 | #ifndef _HAL_MEMORYMAP_H_ 2 | #define _HAL_MEMORYMAP_H_ 3 | 4 | /* 5 | * eFlash 6 | * 7 | * 0 ~ 19 page (20KB) : Loader -> 0x08000000 ~ 0x08004FFF 8 | * 20 ~ 62 page (43KB) : Main FW -> 0x08005000 ~ 0x0800FBFF 9 | * 63 page (1KB) : Keymap -> 0x0800FC00 10 | */ 11 | 12 | extern uint32_t __bss_end__; 13 | 14 | #define TASK_STACK_START ((uint32_t)&__bss_end__) 15 | #define USR_TASK_STACK_SIZE (2 * 1024) 16 | #define TASK_STACK_SIZE (USR_TASK_STACK_SIZE * 3) 17 | 18 | #define EFLASH_TOTALNUM 64 19 | #define EFLASH_START 0x08000000 20 | #define EFLASH_PAGESIZE 0x400 21 | #define EFLASH_BADDR(X) (EFLASH_START + EFLASH_PAGESIZE * (X)) 22 | 23 | #define MAIN_FW_PAGENUM 20 24 | #define MAIN_FW_FLASH_SIZE 43 25 | #define MAIN_FW_ENTRY_OFFSET (MAIN_FW_PAGENUM * EFLASH_PAGESIZE) 26 | #define MAIN_FW_BADDR EFLASH_BADDR(MAIN_FW_PAGENUM) 27 | 28 | #define KEYMAP_PAGENUM (EFLASH_TOTALNUM - 1) /* last page of eFlash */ 29 | #define KEYMAP_BADDR EFLASH_BADDR(KEYMAP_PAGENUM) 30 | 31 | #endif /*_HAL_MEMORYMAP_H_ */ 32 | -------------------------------------------------------------------------------- /doc/Keymap.md: -------------------------------------------------------------------------------- 1 | # Keymap 2 | 3 | Gosu firmware supports configurable key mapping without changing Firmware 4 | binary. It communicates to host using Virtual COM Port (VCP) defined in USB 5 | specification. 6 | 7 | When firmware enters keymap download mode (TBD later), it enables VCP port so 8 | host can initiate keymap transfer. 9 | 10 | ## Keymap structure 11 | 12 | Keymap is binary stream, not using JSON format to help Firmware parse the 13 | content easily. First 4 bytes are CRC(or checksum) of following data stream and 14 | next two bytes indicate the number of rows and colums of the actual keymaps. 15 | Number of layers is pre-defined so that host should send all layer information 16 | even only one layer is used (as of now, Gosu for Coso peak supports two layers). 17 | 18 | { 19 | crc: 32bit 20 | row: 8bit 21 | col: 8bit 22 | keys_t keycodes[NUM_LAYERS][ROW * COL] : 8bit X ROW X COL X NUM_LAYERS 23 | } 24 | 25 | 8bit of actual keycodes are defined in `keymap.h` which adding a few reserved 26 | key code for extended functionality on top of HID scancode. 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Manwoo Yi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app/HostCommTask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * HostCommTask.c 3 | * 4 | * Created on: Feb 9, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdio.h" 9 | #include "stdlib.h" 10 | 11 | #include "usb_hid_keyboard.h" 12 | 13 | #include "KeyHw.h" 14 | #include "keymap.h" 15 | 16 | #include "Kernel.h" 17 | 18 | static void SendUSBHID(void); 19 | 20 | void Host_comm_task(void) 21 | { 22 | DBG_PRINT("Host_comm_task....\n"); 23 | 24 | while (true) 25 | { 26 | KernelEventFlag_t handle_event = Kernel_wait_events(KernelEventFlag_SendD2H); 27 | if (handle_event == KernelEventFlag_SendD2H) 28 | { 29 | SendUSBHID(); 30 | } 31 | Kernel_yield(); 32 | } 33 | } 34 | 35 | static void SendUSBHID(void) 36 | { 37 | uint8_t HIDKeyboardReport[HID_KBD_REPORT_BYTE]; 38 | 39 | Kernel_recv_msg(KernelMsgQ_D2hData, HIDKeyboardReport, HID_KBD_REPORT_BYTE); 40 | 41 | DBG_PRINT("HID: %x %x %x %x\n", HIDKeyboardReport[0], HIDKeyboardReport[1], HIDKeyboardReport[2], HIDKeyboardReport[3]); 42 | 43 | App_hid_send(HIDKeyboardReport, HID_KBD_REPORT_BYTE); 44 | 45 | // ignore unexpected data 46 | Kernel_flush_msg(KernelMsgQ_D2hData); 47 | } 48 | -------------------------------------------------------------------------------- /hal/blackpill/Interrupt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Interrupt.c 3 | * 4 | * Created on: Sep 21, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "memio.h" 10 | #include "HalInterrupt.h" 11 | #include "armcpu.h" 12 | 13 | static InterHdlr_fptr sHandlers[INTERRUPT_HANDLER_NUM]; 14 | 15 | static uint32_t GetInterruptNum(void); 16 | static void ClearInterruptNum(uint32_t n); 17 | 18 | void Hal_interrupt_init(void) 19 | { 20 | enable_irq(); 21 | } 22 | 23 | void Hal_interrupt_enable(uint32_t interrupt_num) 24 | { 25 | 26 | } 27 | 28 | void Hal_interrupt_disable(uint32_t interrupt_num) 29 | { 30 | 31 | } 32 | 33 | void Hal_interrupt_register_handler(InterHdlr_fptr handler, uint32_t interrupt_num) 34 | { 35 | sHandlers[interrupt_num] = handler; 36 | } 37 | 38 | void Hal_interrupt_run_handler(void) 39 | { 40 | uint32_t interrupt_num = GetInterruptNum(); 41 | 42 | if (sHandlers[interrupt_num] != NULL) 43 | { 44 | sHandlers[interrupt_num](); 45 | } 46 | 47 | ClearInterruptNum(interrupt_num); 48 | } 49 | 50 | static uint32_t GetInterruptNum(void) 51 | { 52 | return 0; 53 | } 54 | 55 | static void ClearInterruptNum(uint32_t n) 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /kernel/synch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * synch.c 3 | * 4 | * Created on: Nov 8, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | 11 | #include "synch.h" 12 | 13 | #define DEF_SEM_MAX 8 14 | 15 | static int32_t sSemMax; 16 | static int32_t sSem; 17 | 18 | KernelMutext_t sMutex; 19 | 20 | void Kernel_sem_init(int32_t max) 21 | { 22 | sSemMax = (max <= 0) ? DEF_SEM_MAX : max; 23 | sSemMax = (max >= DEF_SEM_MAX) ? DEF_SEM_MAX : max; 24 | 25 | sSem = sSemMax; 26 | } 27 | 28 | bool Kernel_sem_test(void) 29 | { 30 | if (sSem <= 0) 31 | { 32 | return false; 33 | } 34 | 35 | sSem--; 36 | 37 | return true; 38 | } 39 | 40 | void Kernel_sem_release(void) 41 | { 42 | sSem++; 43 | 44 | if (sSem >= sSemMax) 45 | { 46 | sSem = sSemMax; 47 | } 48 | } 49 | 50 | void Kernel_mutex_init(void) 51 | { 52 | sMutex.owner = 0; 53 | sMutex.lock = false; 54 | } 55 | 56 | bool Kernel_mutex_lock(uint32_t owner) 57 | { 58 | if (sMutex.lock) 59 | { 60 | return false; 61 | } 62 | 63 | sMutex.owner = owner; 64 | sMutex.lock = true; 65 | return true; 66 | } 67 | 68 | bool Kernel_mutex_unlock(uint32_t owner) 69 | { 70 | if (owner == sMutex.owner) 71 | { 72 | sMutex.lock = false; 73 | return true; 74 | } 75 | return false; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /hal/blackpill/Uart.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Uart.c 3 | * 4 | * Created on: Sep 8, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | 11 | #include "stm32f1xx_hal.h" 12 | 13 | #include "Kernel.h" 14 | 15 | UART_HandleTypeDef huart1; 16 | 17 | void Hal_uart_init(void) 18 | { 19 | huart1.Instance = USART1; 20 | huart1.Init.BaudRate = 115200; 21 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 22 | huart1.Init.StopBits = UART_STOPBITS_1; 23 | huart1.Init.Parity = UART_PARITY_NONE; 24 | huart1.Init.Mode = UART_MODE_TX_RX; 25 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 26 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 27 | huart1.gState = HAL_UART_STATE_RESET; 28 | 29 | HAL_UART_Init(&huart1); 30 | 31 | __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE); 32 | 33 | HAL_NVIC_SetPriority(USART1_IRQn, 0, 1); 34 | HAL_NVIC_EnableIRQ(USART1_IRQn); 35 | } 36 | 37 | void Hal_uart_put_char(uint8_t ch) 38 | { 39 | HAL_UART_Transmit(&huart1, &ch, 1, 1000); 40 | } 41 | 42 | uint8_t Hal_uart_get_char(void) 43 | { 44 | uint8_t ch; 45 | HAL_UART_Receive(&huart1, &ch, 1, 1000); 46 | return ch; 47 | } 48 | 49 | void Hal_uart_isr(void) 50 | { 51 | #ifndef LOADER 52 | uint8_t ch = Hal_uart_get_char(); 53 | 54 | if (ch == '\r' || ch == '\n') 55 | { 56 | Hal_uart_put_char('\n'); 57 | 58 | ch = '\0'; 59 | Kernel_send_msg(KernelMsgQ_DebugCmd, &ch, 1); 60 | Kernel_send_events(KernelEventFlag_CmdIn); 61 | } 62 | else 63 | { 64 | Hal_uart_put_char(ch); 65 | Kernel_send_msg(KernelMsgQ_DebugCmd, &ch, 1); 66 | } 67 | #endif 68 | } 69 | 70 | -------------------------------------------------------------------------------- /app/PollingTask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * PollingTask.c 3 | * 4 | * Created on: Feb 9, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdio.h" 9 | #include "stdlib.h" 10 | 11 | #include "usbd_hid.h" 12 | 13 | #include "KeyHw.h" 14 | #include "keymap.h" 15 | 16 | #include "Kernel.h" 17 | 18 | #define HID_KEY_INTERVAL (5) 19 | 20 | void Polling_task(void) 21 | { 22 | DBG_PRINT("Polling Task....\n"); 23 | 24 | bool pressedFnKey = false; 25 | uint32_t pollingCount = 0; 26 | 27 | KeyHwAddr_t hwPollingAddrs[HID_MAX_MULTIPLE_INPUT]; 28 | 29 | uint8_t HIDKeyboardReport[HID_KBD_REPORT_BYTE]; 30 | uint8_t HIDKeyboardReportOld[HID_KBD_REPORT_BYTE]; 31 | 32 | LoadKeymap(); 33 | 34 | while (true) 35 | { 36 | USBD_Delay(HID_KEY_INTERVAL); 37 | 38 | memclr(hwPollingAddrs, HID_MAX_MULTIPLE_INPUT * sizeof(KeyHwAddr_t)); 39 | memclr(HIDKeyboardReport, HID_KBD_REPORT_BYTE); 40 | 41 | pollingCount = KeyHw_polling(hwPollingAddrs, HID_MAX_MULTIPLE_INPUT); 42 | 43 | pressedFnKey = KeyMap_checkFnKey(hwPollingAddrs, pollingCount); 44 | KeyMap_getReport(pressedFnKey, HIDKeyboardReport, hwPollingAddrs, pollingCount); 45 | 46 | if (memncmp(HIDKeyboardReportOld, HIDKeyboardReport, HID_KBD_REPORT_BYTE)) 47 | { 48 | continue; // same input, do not report it 49 | } 50 | 51 | Kernel_send_msg(KernelMsgQ_D2hData, HIDKeyboardReport, HID_KBD_REPORT_BYTE); 52 | Kernel_send_events(KernelEventFlag_SendD2H); 53 | 54 | memncpy(HIDKeyboardReportOld, HIDKeyboardReport, HID_KBD_REPORT_BYTE); 55 | 56 | Kernel_yield(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1998-2014 Free Software Foundation, Inc. 2 | 3 | This file is part of GCC. 4 | 5 | GCC is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 3, or (at your option) 8 | any later version. 9 | 10 | GCC is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | Under Section 7 of GPL version 3, you are granted additional 16 | permissions described in the GCC Runtime Library Exception, version 17 | 3.1, as published by the Free Software Foundation. 18 | 19 | You should have received a copy of the GNU General Public License and 20 | a copy of the GCC Runtime Library Exception along with this program; 21 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 22 | . */ 23 | 24 | /* 25 | * ISO C Standard: 7.16 Boolean type and values 26 | */ 27 | 28 | #ifndef _STDBOOL_H 29 | #define _STDBOOL_H 30 | 31 | #ifndef __cplusplus 32 | 33 | #define bool _Bool 34 | #define true 1 35 | #define false 0 36 | 37 | #else /* __cplusplus */ 38 | 39 | /* Supporting in C++ is a GCC extension. */ 40 | #define _Bool bool 41 | #define bool bool 42 | #define false false 43 | #define true true 44 | 45 | #endif /* __cplusplus */ 46 | 47 | /* Signal that all the definitions are present. */ 48 | #define __bool_true_false_are_defined 1 49 | 50 | #endif /* stdbool.h */ 51 | -------------------------------------------------------------------------------- /lib/cortexM/switch.c: -------------------------------------------------------------------------------- 1 | #include "stdint.h" 2 | #include "stdbool.h" 3 | #include "armcpu.h" 4 | #include "switch.h" 5 | #include "task.h" 6 | 7 | extern KernelTcb_t* gCurrent_tcb; 8 | extern KernelTcb_t* gNext_tcb; 9 | 10 | __attribute__ ((naked)) void Arch_start(void) 11 | { 12 | __asm__ volatile ("MOV r0, #2"); 13 | __asm__ volatile ("MSR control, r0"); 14 | __asm__ volatile ("B Arch_Restore_context"); 15 | } 16 | 17 | __attribute__ ((naked)) void Arch_context_switching(void) 18 | { 19 | __asm__ volatile ("B Arch_Save_context"); 20 | __asm__ volatile ("B Arch_Restore_context"); 21 | } 22 | 23 | __attribute__ ((naked)) void Arch_Save_context(void) 24 | { 25 | // save current task context into the current task stack 26 | __asm__ ("PUSH {lr}"); 27 | __asm__ ("PUSH {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12}"); 28 | __asm__ ("MRS r0, PSR"); 29 | __asm__ ("PUSH {r0}"); 30 | // save current task stack pointer into the current TCB 31 | __asm__ ("LDR r0, =gCurrent_tcb"); 32 | __asm__ ("LDR r0, [r0]"); 33 | __asm__ ("MRS r1, PSP"); 34 | __asm__ ("STMIA r0!,{r1}"); 35 | } 36 | 37 | __attribute__ ((naked)) void Arch_Restore_context(void) 38 | { 39 | // restore next task stack pointer from the next TCB 40 | __asm__ ("LDR r0, =gNext_tcb"); 41 | __asm__ ("LDR r0, [r0]"); 42 | __asm__ ("LDMIA r0!,{r1}"); 43 | __asm__ ("MSR PSP,r1"); 44 | // restore next task context from the next task stack 45 | __asm__ ("POP {r0}"); 46 | __asm__ ("MSR PSR_nzcvq, r0"); 47 | __asm__ ("POP {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12}"); 48 | __asm__ ("POP {pc}"); 49 | } 50 | -------------------------------------------------------------------------------- /kernel/msg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * msg.c 3 | * 4 | * Created on: Nov 6, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | #include "stdlib.h" 11 | 12 | #include "msg.h" 13 | 14 | static KernelCirQ_t sMsgQ[KernelMsgQ_Num]; 15 | 16 | void Kernel_msgQ_init(void) 17 | { 18 | for (uint32_t i = 0 ; i < KernelMsgQ_Num ; i++) 19 | { 20 | sMsgQ[i].front = 0; 21 | sMsgQ[i].rear = 0; 22 | memclr(sMsgQ[i].Queue, MSG_Q_SIZE_BYTE); 23 | } 24 | } 25 | 26 | bool Kernel_msgQ_is_empty(KernelMsgQ_t Qname) 27 | { 28 | if (Qname >= KernelMsgQ_Num) 29 | { 30 | return false; 31 | } 32 | 33 | if (sMsgQ[Qname].front == sMsgQ[Qname].rear) 34 | { 35 | return true; 36 | } 37 | 38 | return false; 39 | } 40 | 41 | bool Kernel_msgQ_is_full(KernelMsgQ_t Qname) 42 | { 43 | if (Qname >= KernelMsgQ_Num) 44 | { 45 | return false; 46 | } 47 | 48 | if (((sMsgQ[Qname].rear + 1) % MSG_Q_SIZE_BYTE) == sMsgQ[Qname].front) 49 | { 50 | return true; 51 | } 52 | 53 | return false; 54 | } 55 | 56 | bool Kernel_msgQ_enqueue(KernelMsgQ_t Qname, uint8_t data) 57 | { 58 | if (Qname >= KernelMsgQ_Num) 59 | { 60 | return false; 61 | } 62 | 63 | if (Kernel_msgQ_is_full(Qname)) 64 | { 65 | return false; 66 | } 67 | sMsgQ[Qname].rear++; 68 | sMsgQ[Qname].rear %= MSG_Q_SIZE_BYTE; 69 | 70 | uint32_t idx = sMsgQ[Qname].rear; 71 | sMsgQ[Qname].Queue[idx] = data; 72 | 73 | return true; 74 | } 75 | 76 | bool Kernel_msgQ_dequeue(KernelMsgQ_t Qname, uint8_t* out_data) 77 | { 78 | if (Qname >= KernelMsgQ_Num) 79 | { 80 | return false; 81 | } 82 | 83 | if (Kernel_msgQ_is_empty(Qname)) 84 | { 85 | return false; 86 | } 87 | 88 | sMsgQ[Qname].front++; 89 | sMsgQ[Qname].front %= MSG_Q_SIZE_BYTE; 90 | 91 | uint32_t idx = sMsgQ[Qname].front; 92 | *out_data = sMsgQ[Qname].Queue[idx]; 93 | 94 | sMsgQ[Qname].Queue[idx] = 0; // clear 95 | 96 | return true; 97 | } 98 | -------------------------------------------------------------------------------- /kernel/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * event.h 3 | * 4 | * Created on: Nov 2, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #ifndef KERNEL_EVENT_H_ 9 | #define KERNEL_EVENT_H_ 10 | 11 | typedef enum KernelEventFlag_t 12 | { 13 | KernelEventFlag_CmdIn = 0x00000001, 14 | KernelEventFlag_SendD2H = 0x00000002, 15 | KernelEventFlag_Reserved02 = 0x00000004, 16 | KernelEventFlag_Reserved03 = 0x00000008, 17 | KernelEventFlag_Reserved04 = 0x00000010, 18 | KernelEventFlag_Reserved05 = 0x00000020, 19 | KernelEventFlag_Reserved06 = 0x00000040, 20 | KernelEventFlag_Reserved07 = 0x00000080, 21 | KernelEventFlag_Reserved08 = 0x00000100, 22 | KernelEventFlag_Reserved09 = 0x00000200, 23 | KernelEventFlag_Reserved10 = 0x00000400, 24 | KernelEventFlag_Reserved11 = 0x00000800, 25 | KernelEventFlag_Reserved12 = 0x00001000, 26 | KernelEventFlag_Reserved13 = 0x00002000, 27 | KernelEventFlag_Reserved14 = 0x00004000, 28 | KernelEventFlag_Reserved15 = 0x00008000, 29 | KernelEventFlag_Reserved16 = 0x00010000, 30 | KernelEventFlag_Reserved17 = 0x00020000, 31 | KernelEventFlag_Reserved18 = 0x00040000, 32 | KernelEventFlag_Reserved19 = 0x00080000, 33 | KernelEventFlag_Reserved20 = 0x00100000, 34 | KernelEventFlag_Reserved21 = 0x00200000, 35 | KernelEventFlag_Reserved22 = 0x00400000, 36 | KernelEventFlag_Reserved23 = 0x00800000, 37 | KernelEventFlag_Reserved24 = 0x01000000, 38 | KernelEventFlag_Reserved25 = 0x02000000, 39 | KernelEventFlag_Reserved26 = 0x04000000, 40 | KernelEventFlag_Reserved27 = 0x08000000, 41 | KernelEventFlag_Reserved28 = 0x10000000, 42 | KernelEventFlag_Reserved29 = 0x20000000, 43 | KernelEventFlag_Reserved30 = 0x40000000, 44 | KernelEventFlag_Reserved31 = 0x80000000, 45 | 46 | KernelEventFlag_Empty = 0x00000000, 47 | } KernelEventFlag_t; 48 | 49 | void Kernel_event_flag_init(void); 50 | void Kernel_event_flag_set(KernelEventFlag_t event); 51 | void Kernel_event_flag_clear(KernelEventFlag_t event); 52 | bool Kernel_event_flag_check(KernelEventFlag_t event); 53 | 54 | #endif /* KERNEL_EVENT_H_ */ 55 | -------------------------------------------------------------------------------- /doc/GettingStarted.md: -------------------------------------------------------------------------------- 1 | # Getting Started 2 | 3 | This guide helps you to get started with building Gosu firmware for Goso Peak 4 | keyboard and following series. After following the steps in this guide, you are 5 | all set to build the firmware and download it to the keyboards. 6 | 7 | ## Conventions in this guide 8 | 9 | ## System requirement 10 | 11 | - Mac OS or Linux system having more than 4GB memory and enough diskspace to 12 | compile ARM GCC. For Linux system, Debian-based (Ubuntu is recommended) 13 | system is assumed. 14 | - ARM GCC, STM32 Flash tool 15 | 16 | ## Install ARM GCC 17 | 18 | Goso Peak and following series of keyboards use ARM controller as its main MCU. 19 | So, to compile the firmware, it requires ARM cross-compiler. You can get ARM GCC 20 | from [ARM developer website][]. You can download platform-specific pre-compiled 21 | binary GCC or compile from the source code. It is assumed to use binary at this 22 | time. 23 | 24 | [ARM developer website]: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads 25 | 26 | Download the binary file and extract it. You just need to copy all files to any 27 | location (recommend `~/.local/`) and put the path `bin/` into `$PATH` 28 | environment variable. 29 | 30 | ## Compiling the Firmware 31 | 32 | ```console 33 | $ ./bluepill.sh 34 | ``` 35 | 36 | After compiling is done, new firmware is created under `out/gosu.bin`. 37 | 38 | ## Download Firmware via USB-UART board 39 | 40 | At this moment, gosu firmware can be downloaded to STM32 dev board for testing 41 | purpose. Downloading firmware to STM32 uses USB-to-UART board as of now. By 42 | default, STM32 controller only supports UART firmware download. It is planned to 43 | support USB firmware download mode after intial firmware is written to internal 44 | eFlash memory. 45 | 46 | ```console 47 | $ ./bluepill.sh burn 48 | ``` 49 | 50 | You need `stm32flash` tool, which can be installed with `sudo apt install 51 | stm32flash` in linux and `brew install stm32flash` in macOS. 52 | 53 | ## Download Firmware via USB 54 | 55 | ### Entering to DFU mode 56 | 57 | ### Download 58 | 59 | ## Changing Keymap 60 | 61 | - Refer [Keymap](Keymap.md) 62 | -------------------------------------------------------------------------------- /kernel/task.c: -------------------------------------------------------------------------------- 1 | /* 2 | * task.c 3 | * 4 | * Created on: Oct 22, 2018 5 | * Author: maanu 6 | */ 7 | 8 | 9 | #include "stdint.h" 10 | #include "stdbool.h" 11 | 12 | #include "PSR.h" 13 | #include "switch.h" 14 | 15 | #include "task.h" 16 | 17 | #include "MemoryMap.h" 18 | 19 | #define MAX_TASK_NUM (TASK_STACK_SIZE / USR_TASK_STACK_SIZE) 20 | 21 | KernelTcb_t* gCurrent_tcb; 22 | KernelTcb_t* gNext_tcb; 23 | 24 | static KernelTcb_t sTask_list[MAX_TASK_NUM]; 25 | static uint32_t sAllocated_tcb_index; 26 | static uint32_t sCurrent_tcb_index; 27 | 28 | static KernelTcb_t* Scheduler_round_robin_algorithm(void); 29 | 30 | void Kernel_task_init(void) 31 | { 32 | sAllocated_tcb_index = 0; 33 | sCurrent_tcb_index = 0; 34 | 35 | for(uint32_t i = 0 ; i < MAX_TASK_NUM ; i++) 36 | { 37 | sTask_list[i].stack_base = (uint8_t*)(TASK_STACK_START + (i * USR_TASK_STACK_SIZE)); 38 | sTask_list[i].sp = (uint32_t)sTask_list[i].stack_base + USR_TASK_STACK_SIZE - 4; 39 | 40 | sTask_list[i].sp -= sizeof(KernelTaskContext_t); 41 | KernelTaskContext_t* ctx = (KernelTaskContext_t*)sTask_list[i].sp; 42 | 43 | ctx->pc = 0; 44 | ctx->spsr = PSR_INIT; 45 | } 46 | } 47 | 48 | void Kernel_task_start(void) 49 | { 50 | gNext_tcb = &sTask_list[sCurrent_tcb_index]; 51 | Arch_start(); 52 | } 53 | 54 | uint32_t Kernel_task_create(KernelTaskFunc_t startFunc) 55 | { 56 | KernelTcb_t* new_tcb = &sTask_list[sAllocated_tcb_index++]; 57 | 58 | if (sAllocated_tcb_index > MAX_TASK_NUM) 59 | { 60 | return NOT_ENOUGH_TASK_NUM; 61 | } 62 | 63 | KernelTaskContext_t* ctx = (KernelTaskContext_t*)new_tcb->sp; 64 | ctx->pc = (uint32_t)startFunc; 65 | 66 | return (sAllocated_tcb_index - 1); 67 | } 68 | 69 | uint32_t Kernel_task_get_current_task_id(void) 70 | { 71 | return sCurrent_tcb_index; 72 | } 73 | 74 | void Kernel_task_scheduler(void) 75 | { 76 | gCurrent_tcb = &sTask_list[sCurrent_tcb_index]; 77 | gNext_tcb = Scheduler_round_robin_algorithm(); 78 | 79 | Arch_context_switching(); 80 | } 81 | 82 | static KernelTcb_t* Scheduler_round_robin_algorithm(void) 83 | { 84 | sCurrent_tcb_index++; 85 | sCurrent_tcb_index %= sAllocated_tcb_index; 86 | 87 | return &sTask_list[sCurrent_tcb_index]; 88 | } 89 | -------------------------------------------------------------------------------- /lib/stdlib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * stdlib.c 3 | * 4 | * Created on: Sep 27, 2018 5 | * Author: yiman 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdbool.h" 10 | #include "stdio.h" 11 | 12 | #include "HalTimer.h" 13 | 14 | 15 | void delay(uint32_t ms) 16 | { 17 | uint32_t goal = Hal_timer_get_1ms_counter() + ms; 18 | 19 | while(goal != Hal_timer_get_1ms_counter()); 20 | } 21 | 22 | void memclr(void* dst, uint32_t count) 23 | { 24 | uint8_t* d = (uint8_t*)dst; 25 | 26 | while(count--) 27 | { 28 | *d++ = 0; 29 | } 30 | } 31 | 32 | uint32_t memfind(uint8_t* src, uint8_t byte, uint32_t count) 33 | { 34 | for(uint32_t i = 0 ; i < count ; i++) 35 | { 36 | if (*src++ == byte) 37 | { 38 | return i; 39 | } 40 | } 41 | return (count + 1); 42 | } 43 | 44 | bool memncmp(uint8_t* m1, uint8_t* m2, uint32_t count) 45 | { 46 | while(count--) 47 | { 48 | if (*m1++ != *m2++) 49 | { 50 | return false; 51 | } 52 | } 53 | 54 | return true; 55 | } 56 | 57 | void memncpy(uint8_t* dst, uint8_t* src, uint32_t count) 58 | { 59 | while(count--) 60 | { 61 | *dst++ = *src++; 62 | } 63 | } 64 | 65 | uint32_t htou(char* ascii, uint32_t count) 66 | { 67 | uint32_t ret = 0; 68 | while(count--) 69 | { 70 | uint32_t digit = 0; 71 | if ('0' <= *ascii && *ascii <= '9') 72 | { 73 | digit = *ascii - '0'; 74 | } 75 | else if ('a' <= *ascii && *ascii <= 'f') 76 | { 77 | digit = *ascii - 'a' + 10; 78 | } 79 | else if ('A' <= *ascii && *ascii <= 'F') 80 | { 81 | digit = *ascii - 'A' + 10; 82 | } 83 | else 84 | { 85 | return 0; 86 | } 87 | ascii++; 88 | ret += digit * (1 << (count*4)); 89 | } 90 | 91 | return ret; 92 | } 93 | 94 | uint32_t strncnt(char* str, uint32_t max_len) 95 | { 96 | uint32_t cnt = 0; 97 | 98 | for (uint32_t i = 0 ; i < max_len ; i++) 99 | { 100 | if (*str == '\0') 101 | { 102 | break; 103 | } 104 | cnt++; 105 | str++; 106 | } 107 | 108 | return cnt; 109 | } 110 | 111 | void halt(char* filename, uint32_t line) 112 | { 113 | DBG_PRINT("HALT [%s] at (%u)\n", filename, line); 114 | while(1); 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gosu 2 | 3 | Gosu is the mechanical keyboard firmware based on the Navilos(https://github.com/navilera/navilos) RTOS. Currently, Gosu supports ARM Cortex-M3 controller which is STM32F103. Gosu has flexible design so it can be extended to many other contollers. 4 | 5 | ## Features 6 | 7 | *HID USB Keyboard* 8 | It is the core firmware feature. This main firmware should be loaded by MSC loader. 9 | 10 | *MSC (Mass Storage Class) loader* 11 | Gosu supports firmware/keymap updating feature via mass storage device. It doesn't need any burner equipment like serial-to-USB or ICE. It needs one of these equipment only one time to download MSC loader at the first time. After download MSC loader, It upgrade a firmware or a keymap by itself. Just drag a binary file and drop it into a mass storage drive. 12 | 13 | *Keymap editor* 14 | This Keymap editor is based on TMK keymap editor(http://www.tmk-kbd.com/tmk_keyboard/editor/). It is very easy to use and it has an intuitive user interface. The keymap editor generates a keymap binary file. This keymap binary file should be loaded by MSC loader. 15 | 16 | ## Build and download firmware 17 | 18 | Gosu currently supports a bluepill and blackpill board which are very cheap STM32F103 based boards. Gosu has working (and sample) code and build environment(Makefile) for bluepill board. For make MSC loader binary file, please do following command. 19 | 20 | > ./bluepill_loader.sh 21 | 22 | That is all. It generates /out/loader.bin file. Then, do following command to download MSC loader into a bluepill or blackpill board after jumper setting. 23 | 24 | > ./bluepill_loader.sh burn 25 | 26 | For make main firmware binary file, please do following command. 27 | 28 | > ./bluepill.sh 29 | 30 | It generates /out/gosu.bin file. Please disconnect USB cable from bluepill or blackpill board and then press ESC key, keep pressing ESC key and re-connect USB case to bluepill board. Once it runs a MSC loader, the OS (Linux or Windows or OSX etc.) shows a mounted mass storage drive in file manager program. It is exactly same as using USB thumb drive. Finally, Just drag and drop the /out/gosu.bin file. 31 | 32 | ## Custom Keymap 33 | 34 | User can make a their own custom keymap using the keymap editor. The keymap editor implemented by HTML so, User can use the keymap editor by run web browser. 35 | 36 | ## Documents 37 | 38 | - [Getting Started](doc/GettingStarted.md) 39 | - [How to contribute](doc/Contribute.md) 40 | -------------------------------------------------------------------------------- /tool/keymapeditor/keyboard.css: -------------------------------------------------------------------------------- 1 | html * { 2 | font-family:helvetica, arial, sans-serif; 3 | } 4 | 5 | .key { 6 | box-shadow:inset -3px -3px 5px 5px #ebebeb; 7 | background-color:#ffffff; 8 | -moz-border-radius:6px; 9 | -webkit-border-radius:6px; 10 | border-radius:6px; 11 | border:2px solid #dcdcdc; 12 | display:block; 13 | float: left; 14 | color:#777777; 15 | font-family:helvetica, arial, sans-serif; 16 | font-size:16px; 17 | font-weight:bold; 18 | text-decoration:none; 19 | padding:4px 16px 16px 4px; 20 | width: 24px; 21 | height: 24px; 22 | overflow: hidden; 23 | margin: 0px 1px 1px 0px; 24 | } 25 | .key:hover { 26 | background-color:#ebebeb; 27 | } 28 | .key:active { 29 | } 30 | .key:focus { 31 | } 32 | .key-editing { 33 | //background-color:#bfbfbf; 34 | border:2px solid #7f7f7f; 35 | position:relative; 36 | //top:2px; 37 | } 38 | /* This imageless css button was generated by CSSButtonGenerator.com */ 39 | 40 | /* Key size and pixel 41 | * key: 1.00 1.25 1.50 1.75 2.00 42 | * size: 50 62.5 75 87.5 100 43 | * width: 24 36.5 49 61.5 74 44 | * 45 | * margin:1 + border:2 + padding:4 + width:24 + padding:16 + border:2 + margin:1 = 50px 46 | * width:24 + 26px = 50px 47 | */ 48 | .btn100 { width:24px; } 49 | .btn125 { width:36.5px; } 50 | .btn150 { width:47.5px; } 51 | .btn175 { width:60px; } 52 | .btn200 { width:74px; } 53 | .btn225 { width:83px; } 54 | .btn250 { width:99px; } 55 | .btn275 { width:111.5px; } 56 | .btn600 { width:259px; } 57 | .btn625 { width:270px; } 58 | .btn700 { width:324px; } 59 | 60 | .f_spc { width:20px; height:1px; visibility:hidden; float:left; display:block; } 61 | 62 | .spc025 { width:0px; visibility:hidden; } 63 | .spc030 { width:20px; visibility:hidden; } 64 | .spc100 { width:24px; visibility:hidden; } 65 | .spc125 { width:36.5px; visibility:hidden; } 66 | .spc150 { width:47.5px; visibility:hidden; } 67 | .spc175 { width:60px; visibility:hidden; } 68 | .spc200 { width 74px; visibility:hidden; } 69 | 70 | .keyboard-row { 71 | width: auto; 72 | display: inline-block; 73 | } 74 | 75 | .keyboard-outline { 76 | } 77 | 78 | .keyboard-pane { 79 | width: 900px; 80 | font-size: 14px; 81 | font-weight:bold; 82 | } 83 | 84 | 85 | 86 | .action { 87 | font-size:16px; 88 | font-weight:bold; 89 | min-width: 30px; 90 | } 91 | 92 | .keycode_tabs { 93 | max-width: 750px; 94 | overflow: auto; 95 | font-size:14px; 96 | font-weight:bold; 97 | } 98 | 99 | 100 | 101 | /* http://www.w3schools.com/cssref/css3_pr_resize.asp */ 102 | .resizable { 103 | resize: both; 104 | overflow: auto; 105 | } 106 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc_data.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_data.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header for the usbd_msc_data.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_MSC_DATA_H 30 | #define __USBD_MSC_DATA_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_conf.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USB_INFO 44 | * @brief general defines for the usb device library file 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USB_INFO_Exported_Defines 49 | * @{ 50 | */ 51 | #define MODE_SENSE6_LEN 8 52 | #define MODE_SENSE10_LEN 8 53 | #define LENGTH_INQUIRY_PAGE00 7 54 | #define LENGTH_FORMAT_CAPACITIES 20 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_INFO_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | /** 65 | * @} 66 | */ 67 | 68 | 69 | 70 | /** @defgroup USBD_INFO_Exported_Macros 71 | * @{ 72 | */ 73 | 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup USBD_INFO_Exported_Variables 79 | * @{ 80 | */ 81 | extern const uint8_t MSC_Page00_Inquiry_Data[]; 82 | extern const uint8_t MSC_Mode_Sense6_data[]; 83 | extern const uint8_t MSC_Mode_Sense10_data[] ; 84 | 85 | /** 86 | * @} 87 | */ 88 | 89 | /** @defgroup USBD_INFO_Exported_FunctionsPrototype 90 | * @{ 91 | */ 92 | 93 | /** 94 | * @} 95 | */ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __USBD_MSC_DATA_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 112 | -------------------------------------------------------------------------------- /lib/stdio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * stdio.c 3 | * 4 | * Created on: Sep 17, 2018 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdint.h" 9 | #include "stdio.h" 10 | 11 | #include "armcpu.h" 12 | #include "HalUart.h" 13 | 14 | #define PRINTF_BUF_LEN 64 15 | 16 | void dummy_print(const char* format, ...) 17 | { 18 | return; 19 | } 20 | 21 | uint32_t putstr(const char* s) 22 | { 23 | uint32_t c = 0; 24 | while(*s) 25 | { 26 | Hal_uart_put_char(*s++); 27 | c++; 28 | } 29 | return c; 30 | } 31 | 32 | uint32_t debug_printf(const char* format, ...) 33 | { 34 | char printf_buf[PRINTF_BUF_LEN] = {0}; 35 | 36 | disable_irq(); 37 | 38 | va_list args; 39 | va_start(args, format); 40 | vsprintf(printf_buf, format, args); 41 | va_end(args); 42 | 43 | uint32_t outnum = putstr(printf_buf); 44 | 45 | enable_irq(); 46 | 47 | return outnum; 48 | } 49 | 50 | uint32_t vsprintf(char* buf, const char* format, va_list arg) 51 | { 52 | uint32_t c = 0; 53 | 54 | char ch; 55 | char* str; 56 | uint32_t uint; 57 | uint32_t hex; 58 | 59 | for (uint32_t i = 0 ; format[i] ; i++) 60 | { 61 | if (format[i] == '%') 62 | { 63 | i++; 64 | switch(format[i]) 65 | { 66 | case 'c': 67 | ch = (char)va_arg(arg, int32_t); 68 | buf[c++] = ch; 69 | break; 70 | case 's': 71 | str = (char*)va_arg(arg, char*); 72 | if (str == NULL) 73 | { 74 | str = "(null)"; 75 | } 76 | while(*str) 77 | { 78 | buf[c++] = (*str++); 79 | } 80 | break; 81 | case 'u': 82 | uint = (uint32_t)va_arg(arg, uint32_t); 83 | c += utoa(&buf[c], uint, utoa_dec); 84 | break; 85 | case 'x': 86 | hex = (uint32_t)va_arg(arg, uint32_t); 87 | c += utoa(&buf[c], hex, utoa_hex); 88 | break; 89 | } 90 | } 91 | else 92 | { 93 | buf[c++] = format[i]; 94 | } 95 | } 96 | 97 | if (c >= PRINTF_BUF_LEN) 98 | { 99 | buf[0] = '\0'; 100 | return 0; 101 | } 102 | 103 | buf[c] = '\0'; 104 | return c; 105 | } 106 | 107 | uint32_t utoa(char* buf, uint32_t val, utoa_t base) 108 | { 109 | uint32_t c = 0; 110 | int32_t idx = 0; 111 | char tmp[11]; // It is big enough for store 32 bit int 112 | 113 | do { 114 | uint32_t t = val % (uint32_t)base; 115 | if (t >= 10) 116 | { 117 | t += 'A' - '0' - 10; 118 | } 119 | tmp[idx] = (t + '0'); 120 | val /= base; 121 | idx++; 122 | } while(val); 123 | 124 | // reverse 125 | idx--; 126 | while (idx >= 0) 127 | { 128 | buf[c++] = tmp[idx]; 129 | idx--; 130 | } 131 | 132 | return c; 133 | } 134 | -------------------------------------------------------------------------------- /app/blackpill/HID/usbd_hid_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_desc.h 4 | * @version : v2.0_Cube 5 | * @brief : Header for usbd_desc file. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2017 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | #ifndef __USBD_HID_DESC__H__ 51 | #define __USBD_HID_DESC__H__ 52 | 53 | #include "usbd_def.h" 54 | 55 | #endif /* __USBD_DESC_H */ 56 | 57 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc_data.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_data.c 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief This file provides all the vital inquiry pages and sense data. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 "usbd_msc_data.h" 30 | 31 | 32 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 33 | * @{ 34 | */ 35 | 36 | 37 | /** @defgroup MSC_DATA 38 | * @brief Mass storage info/data module 39 | * @{ 40 | */ 41 | 42 | /** @defgroup MSC_DATA_Private_TypesDefinitions 43 | * @{ 44 | */ 45 | /** 46 | * @} 47 | */ 48 | 49 | 50 | /** @defgroup MSC_DATA_Private_Defines 51 | * @{ 52 | */ 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup MSC_DATA_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup MSC_DATA_Private_Variables 67 | * @{ 68 | */ 69 | 70 | 71 | /* USB Mass storage Page 0 Inquiry Data */ 72 | const uint8_t MSC_Page00_Inquiry_Data[] = {//7 73 | 0x00, 74 | 0x00, 75 | 0x00, 76 | (LENGTH_INQUIRY_PAGE00 - 4), 77 | 0x00, 78 | 0x80, 79 | 0x83 80 | }; 81 | /* USB Mass storage sense 6 Data */ 82 | const uint8_t MSC_Mode_Sense6_data[] = { 83 | 0x00, 84 | 0x00, 85 | 0x00, 86 | 0x00, 87 | 0x00, 88 | 0x00, 89 | 0x00, 90 | 0x00 91 | }; 92 | /* USB Mass storage sense 10 Data */ 93 | const uint8_t MSC_Mode_Sense10_data[] = { 94 | 0x00, 95 | 0x06, 96 | 0x00, 97 | 0x00, 98 | 0x00, 99 | 0x00, 100 | 0x00, 101 | 0x00 102 | }; 103 | /** 104 | * @} 105 | */ 106 | 107 | 108 | /** @defgroup MSC_DATA_Private_FunctionPrototypes 109 | * @{ 110 | */ 111 | /** 112 | * @} 113 | */ 114 | 115 | 116 | /** @defgroup MSC_DATA_Private_Functions 117 | * @{ 118 | */ 119 | 120 | /** 121 | * @} 122 | */ 123 | 124 | 125 | /** 126 | * @} 127 | */ 128 | 129 | 130 | /** 131 | * @} 132 | */ 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /app/blackpill/USB/usbd_ctlreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_req.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header file for the usbd_req.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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_REQUEST_H 30 | #define __USB_REQUEST_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_REQ 45 | * @brief header file for the usbd_req.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_REQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_REQ_Exported_Types 58 | * @{ 59 | */ 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | 66 | /** @defgroup USBD_REQ_Exported_Macros 67 | * @{ 68 | */ 69 | /** 70 | * @} 71 | */ 72 | 73 | /** @defgroup USBD_REQ_Exported_Variables 74 | * @{ 75 | */ 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype 81 | * @{ 82 | */ 83 | 84 | USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 85 | USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 86 | USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 87 | 88 | 89 | void USBD_CtlError (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req); 90 | 91 | void USBD_ParseSetupRequest (USBD_SetupReqTypedef *req, uint8_t *pdata); 92 | 93 | void USBD_GetString (uint8_t *desc, uint8_t *unicode, uint16_t *len); 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* __USB_REQUEST_H */ 103 | 104 | /** 105 | * @} 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | 113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 114 | -------------------------------------------------------------------------------- /app/blackpill/KeyHw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * KeyHw.c 3 | * 4 | * Created on: Feb 11, 2019 5 | * Author: maanu 6 | */ 7 | #include "KeyHw.h" 8 | #include "keymap.h" 9 | #include "Layout.h" 10 | 11 | #include "stm32f1xx_hal.h" 12 | 13 | static void SetAllRowToLow(void); 14 | static void SetAllColToInput(void); 15 | static void SetRowToHigh(uint32_t idx); 16 | static void SetRowToLow(uint32_t idx); 17 | static bool GetColInput(uint32_t idx); 18 | 19 | uint32_t KeyHw_polling(KeyHwAddr_t* keyHwAddrBuff, uint32_t max_count) 20 | { 21 | uint32_t cnt = 0; 22 | 23 | SetAllRowToLow(); 24 | SetAllColToInput(); 25 | 26 | HAL_Delay(1); 27 | 28 | bool pressed = false; 29 | 30 | for (uint32_t row = 0 ; row < KEYMAP_ROW_NUM ; row++) 31 | { 32 | SetRowToHigh(row); 33 | HAL_Delay(1); 34 | 35 | for (uint32_t col = 0 ; col < KEYMAP_COL_NUM ; col++) 36 | { 37 | pressed = GetColInput(col); 38 | 39 | if (pressed) 40 | { 41 | if (cnt > 0) 42 | { 43 | if (keyHwAddrBuff->row == (uint8_t)row && keyHwAddrBuff->col == (uint8_t)col) 44 | { 45 | continue; 46 | } 47 | else 48 | { 49 | keyHwAddrBuff++; 50 | } 51 | } 52 | 53 | keyHwAddrBuff->row = (uint8_t)row; 54 | keyHwAddrBuff->col = (uint8_t)col; 55 | 56 | DBG_PRINT("HW Polling (R:%u C:%u) %u\n", row, col, cnt); 57 | 58 | cnt++; 59 | 60 | if (cnt > max_count) 61 | { 62 | return cnt; 63 | } 64 | } 65 | } 66 | 67 | SetRowToLow(row); 68 | } 69 | 70 | return cnt; 71 | } 72 | 73 | bool KeyHw_IsPressed(uint32_t col, uint32_t row) 74 | { 75 | bool isPressed = false; 76 | 77 | SetAllRowToLow(); 78 | SetAllColToInput(); 79 | 80 | SetRowToHigh(row); 81 | HAL_Delay(1); 82 | isPressed = GetColInput(col); 83 | 84 | return isPressed; 85 | } 86 | 87 | static void SetAllRowToLow(void) 88 | { 89 | GPIO_InitTypeDef GPIO_InitStruct; 90 | 91 | for (uint32_t row = 0 ; row < KEYMAP_ROW_NUM ; row++) 92 | { 93 | GPIO_InitStruct.Pin = gRowPin[row].num; 94 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 95 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 96 | 97 | HAL_GPIO_Init((GPIO_TypeDef*)gRowPin[row].port, &GPIO_InitStruct); 98 | HAL_GPIO_WritePin((GPIO_TypeDef*)gRowPin[row].port, gRowPin[row].num, GPIO_PIN_RESET); 99 | } 100 | } 101 | 102 | static void SetAllColToInput(void) 103 | { 104 | GPIO_InitTypeDef GPIO_InitStruct; 105 | 106 | for (uint32_t col = 0 ; col < KEYMAP_COL_NUM ; col++) 107 | { 108 | GPIO_InitStruct.Pin = gColPin[col].num; 109 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 110 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 111 | 112 | HAL_GPIO_Init((GPIO_TypeDef*)gColPin[col].port, &GPIO_InitStruct); 113 | } 114 | } 115 | 116 | static void SetRowToHigh(uint32_t idx) 117 | { 118 | HAL_GPIO_WritePin((GPIO_TypeDef*)gRowPin[idx].port, gRowPin[idx].num, GPIO_PIN_SET); 119 | } 120 | 121 | static void SetRowToLow(uint32_t idx) 122 | { 123 | HAL_GPIO_WritePin((GPIO_TypeDef*)gRowPin[idx].port, gRowPin[idx].num, GPIO_PIN_RESET); 124 | } 125 | 126 | static bool GetColInput(uint32_t idx) 127 | { 128 | return (bool)HAL_GPIO_ReadPin((GPIO_TypeDef*)gColPin[idx].port, gColPin[idx].num); 129 | } 130 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f1xx_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.h 4 | * @brief This file contains the headers of the interrupt handlers. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | 34 | /* Define to prevent recursive inclusion -------------------------------------*/ 35 | #ifndef __STM32F1xx_IT_H 36 | #define __STM32F1xx_IT_H 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Includes ------------------------------------------------------------------*/ 43 | /* Exported types ------------------------------------------------------------*/ 44 | /* Exported constants --------------------------------------------------------*/ 45 | /* Exported macro ------------------------------------------------------------*/ 46 | /* Exported functions ------------------------------------------------------- */ 47 | 48 | void NMI_Handler(void); 49 | void HardFault_Handler(void); 50 | void MemManage_Handler(void); 51 | void BusFault_Handler(void); 52 | void UsageFault_Handler(void); 53 | void SVC_Handler(void); 54 | void DebugMon_Handler(void); 55 | void PendSV_Handler(void); 56 | void SysTick_Handler(void); 57 | void USB_LP_CAN1_RX0_IRQHandler(void); 58 | void USART1_IRQHandler(void); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* __STM32F1xx_IT_H */ 65 | 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc_desc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_desc.h 4 | * @version : v2.0_Cube 5 | * @brief : Header for usbd_desc file. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2018 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Define to prevent recursive inclusion -------------------------------------*/ 51 | #ifndef __USBD_MSC_DESC__H__ 52 | #define __USBD_MSC_DESC__H__ 53 | 54 | #include "usbd_def.h" 55 | 56 | 57 | #endif /* __USBD_DESC_H */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 67 | -------------------------------------------------------------------------------- /kernel/Kernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Kernel.c 3 | * 4 | * Created on: Oct 28, 2018 5 | * Author: maanu 6 | */ 7 | 8 | 9 | #include "stdint.h" 10 | #include "stdbool.h" 11 | 12 | #include "armcpu.h" 13 | #include "memio.h" 14 | #include "Kernel.h" 15 | 16 | void Kernel_start(void) 17 | { 18 | enable_irq(); 19 | Kernel_task_start(); 20 | } 21 | 22 | void Kernel_yield(void) 23 | { 24 | Kernel_task_scheduler(); 25 | } 26 | 27 | void Kernel_send_events(uint32_t event_list) 28 | { 29 | KernelEventFlag_t sending_event = KernelEventFlag_Empty; 30 | 31 | for (uint32_t i = 0 ; i < 32 ; i++) 32 | { 33 | if ((event_list >> i) & 1) 34 | { 35 | SET_BIT(sending_event, i); 36 | Kernel_event_flag_set(sending_event); 37 | } 38 | } 39 | } 40 | 41 | KernelEventFlag_t Kernel_wait_events(uint32_t waiting_list) 42 | { 43 | KernelEventFlag_t waiting_event = KernelEventFlag_Empty; 44 | 45 | for (uint32_t i = 0 ; i < 32 ; i++) 46 | { 47 | if ((waiting_list >> i) & 1) 48 | { 49 | SET_BIT(waiting_event, i); 50 | 51 | if (Kernel_event_flag_check(waiting_event)) 52 | { 53 | return waiting_event; 54 | } 55 | } 56 | } 57 | 58 | return KernelEventFlag_Empty; 59 | } 60 | 61 | bool Kernel_send_msg(KernelMsgQ_t Qname, void* data, uint32_t count) 62 | { 63 | uint8_t* d = (uint8_t*)data; 64 | 65 | for (uint32_t i = 0 ; i < count ; i++) 66 | { 67 | if (false == Kernel_msgQ_enqueue(Qname, *d)) 68 | { 69 | for (uint32_t j = 0 ; j < i ; j++) 70 | { 71 | uint8_t rollback; 72 | Kernel_msgQ_dequeue(Qname, &rollback); 73 | } 74 | return false; 75 | } 76 | d++; 77 | } 78 | 79 | return true; 80 | } 81 | 82 | uint32_t Kernel_recv_msg(KernelMsgQ_t Qname, void* out_data, uint32_t count) 83 | { 84 | uint8_t* d = (uint8_t*)out_data; 85 | 86 | for (uint32_t i = 0 ; i < count ; i++) 87 | { 88 | if (false == Kernel_msgQ_dequeue(Qname, d)) 89 | { 90 | return i; 91 | } 92 | d++; 93 | } 94 | 95 | return count; 96 | } 97 | 98 | void Kernel_flush_msg(KernelMsgQ_t Qname) 99 | { 100 | uint8_t d = 0; 101 | 102 | while(true) 103 | { 104 | if (false == Kernel_msgQ_dequeue(Qname, &d)) 105 | { 106 | break; 107 | } 108 | } 109 | } 110 | 111 | void Kernel_lock_sem(void) 112 | { 113 | while(false == Kernel_sem_test()) 114 | { 115 | Kernel_yield(); 116 | } 117 | } 118 | 119 | void Kernel_unlock_sem(void) 120 | { 121 | Kernel_sem_release(); 122 | } 123 | 124 | void Kernel_lock_mutex(void) 125 | { 126 | while(true) 127 | { 128 | uint32_t current_task_id = Kernel_task_get_current_task_id(); 129 | if (false == Kernel_mutex_lock(current_task_id)) 130 | { 131 | Kernel_yield(); 132 | } 133 | else 134 | { 135 | break; 136 | } 137 | } 138 | } 139 | 140 | void Kernel_unlock_mutex(void) 141 | { 142 | uint32_t current_task_id = Kernel_task_get_current_task_id(); 143 | if (false == Kernel_mutex_unlock(current_task_id)) 144 | { 145 | Kernel_yield(); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usb_msc_device.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v2.0_Cube 5 | * @brief : Header for usb_device file. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2018 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | #ifndef __usb_msc_device_H 51 | #define __usb_msc_device_H 52 | 53 | 54 | /* USB_Device init function */ 55 | void App_msc_Init(void); 56 | 57 | #endif /*__usb_device_H */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 68 | -------------------------------------------------------------------------------- /app/blackpill/HID/usb_hid_keyboard.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v2.0_Cube 5 | * @brief : Header for usb_device file. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2017 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | #ifndef __usb_hid_device_H 51 | #define __usb_hid_device_H 52 | 53 | /* Includes ------------------------------------------------------------------*/ 54 | #include "stm32f1xx.h" 55 | #include "stm32f1xx_hal.h" 56 | #include "usbd_def.h" 57 | 58 | #include "stdbool.h" 59 | 60 | /* USB_Device init function */ 61 | void App_hid_Init(void); 62 | 63 | void App_hid_send(const void *data,const size_t size); 64 | 65 | bool USBD_HID_Is_Configured(void); 66 | 67 | #endif /*__usb_device_H */ 68 | 69 | -------------------------------------------------------------------------------- /app/blackpill/USB/usbd_ioreq.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header file for the usbd_ioreq.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_IOREQ_H 30 | #define __USBD_IOREQ_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | #include "usbd_core.h" 39 | 40 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 41 | * @{ 42 | */ 43 | 44 | /** @defgroup USBD_IOREQ 45 | * @brief header file for the usbd_ioreq.c file 46 | * @{ 47 | */ 48 | 49 | /** @defgroup USBD_IOREQ_Exported_Defines 50 | * @{ 51 | */ 52 | /** 53 | * @} 54 | */ 55 | 56 | 57 | /** @defgroup USBD_IOREQ_Exported_Types 58 | * @{ 59 | */ 60 | 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | 67 | 68 | /** @defgroup USBD_IOREQ_Exported_Macros 69 | * @{ 70 | */ 71 | 72 | /** 73 | * @} 74 | */ 75 | 76 | /** @defgroup USBD_IOREQ_Exported_Variables 77 | * @{ 78 | */ 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype 85 | * @{ 86 | */ 87 | 88 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 89 | uint8_t *buf, 90 | uint16_t len); 91 | 92 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 93 | uint8_t *pbuf, 94 | uint16_t len); 95 | 96 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 97 | uint8_t *pbuf, 98 | uint16_t len); 99 | 100 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 101 | uint8_t *pbuf, 102 | uint16_t len); 103 | 104 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev); 105 | 106 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev); 107 | 108 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , 109 | uint8_t epnum); 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* __USBD_IOREQ_H */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** 126 | * @} 127 | */ 128 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 129 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/system_stm32f1xx.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V4.2.0 6 | * @date 31-March-2017 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2017 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /** @addtogroup CMSIS 39 | * @{ 40 | */ 41 | 42 | /** @addtogroup stm32f10x_system 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief Define to prevent recursive inclusion 48 | */ 49 | #ifndef __SYSTEM_STM32F10X_H 50 | #define __SYSTEM_STM32F10X_H 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | /** @addtogroup STM32F10x_System_Includes 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | 65 | /** @addtogroup STM32F10x_System_Exported_types 66 | * @{ 67 | */ 68 | 69 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 70 | extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */ 71 | extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @addtogroup STM32F10x_System_Exported_Constants 78 | * @{ 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @addtogroup STM32F10x_System_Exported_Macros 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** @addtogroup STM32F10x_System_Exported_Functions 94 | * @{ 95 | */ 96 | 97 | extern void SystemInit(void); 98 | extern void SystemCoreClockUpdate(void); 99 | /** 100 | * @} 101 | */ 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /*__SYSTEM_STM32F10X_H */ 108 | 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 117 | -------------------------------------------------------------------------------- /lib/cortexM/core_cmFunc.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmFunc.h 3 | * @brief CMSIS Cortex-M Core Function Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMFUNC_H 42 | #define __CORE_CMFUNC_H 43 | 44 | 45 | /* ########################### Core Function Access ########################### */ 46 | /** \ingroup CMSIS_Core_FunctionInterface 47 | \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@} end of CMSIS_Core_RegAccFunctions */ 86 | 87 | #endif /* __CORE_CMFUNC_H */ 88 | -------------------------------------------------------------------------------- /lib/cortexM/core_cmInstr.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file core_cmInstr.h 3 | * @brief CMSIS Cortex-M Core Instruction Access Header File 4 | * @version V4.30 5 | * @date 20. October 2015 6 | ******************************************************************************/ 7 | /* Copyright (c) 2009 - 2015 ARM LIMITED 8 | 9 | All rights reserved. 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are met: 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | - Neither the name of ARM nor the names of its contributors may be used 18 | to endorse or promote products derived from this software without 19 | specific prior written permission. 20 | * 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | ---------------------------------------------------------------------------*/ 33 | 34 | 35 | #if defined ( __ICCARM__ ) 36 | #pragma system_include /* treat file as system include file for MISRA check */ 37 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 38 | #pragma clang system_header /* treat file as system include file */ 39 | #endif 40 | 41 | #ifndef __CORE_CMINSTR_H 42 | #define __CORE_CMINSTR_H 43 | 44 | 45 | /* ########################## Core Instruction Access ######################### */ 46 | /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface 47 | Access to dedicated instructions 48 | @{ 49 | */ 50 | 51 | /*------------------ RealView Compiler -----------------*/ 52 | #if defined ( __CC_ARM ) 53 | #include "cmsis_armcc.h" 54 | 55 | /*------------------ ARM Compiler V6 -------------------*/ 56 | #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) 57 | #include "cmsis_armcc_V6.h" 58 | 59 | /*------------------ GNU Compiler ----------------------*/ 60 | #elif defined ( __GNUC__ ) 61 | #include "cmsis_gcc.h" 62 | 63 | /*------------------ ICC Compiler ----------------------*/ 64 | #elif defined ( __ICCARM__ ) 65 | #include 66 | 67 | /*------------------ TI CCS Compiler -------------------*/ 68 | #elif defined ( __TMS470__ ) 69 | #include 70 | 71 | /*------------------ TASKING Compiler ------------------*/ 72 | #elif defined ( __TASKING__ ) 73 | /* 74 | * The CMSIS functions have been implemented as intrinsics in the compiler. 75 | * Please use "carm -?i" to get an up to date list of all intrinsics, 76 | * Including the CMSIS ones. 77 | */ 78 | 79 | /*------------------ COSMIC Compiler -------------------*/ 80 | #elif defined ( __CSMC__ ) 81 | #include 82 | 83 | #endif 84 | 85 | /*@}*/ /* end of group CMSIS_Core_InstructionInterface */ 86 | 87 | #endif /* __CORE_CMINSTR_H */ 88 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_storage_if.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_storage_if.h 4 | * @brief : header file for the usbd_storage_if.c file 5 | ****************************************************************************** 6 | * This notice applies to any and all portions of this file 7 | * that are not between comment pairs USER CODE BEGIN and 8 | * USER CODE END. Other portions of this file, whether 9 | * inserted by the user or by software development tools 10 | * are owned by their respective copyright owners. 11 | * 12 | * Copyright (c) 2018 STMicroelectronics International N.V. 13 | * All rights reserved. 14 | * 15 | * Redistribution and use in source and binary forms, with or without 16 | * modification, are permitted, provided that the following conditions are met: 17 | * 18 | * 1. Redistribution of source code must retain the above copyright notice, 19 | * this list of conditions and the following disclaimer. 20 | * 2. Redistributions in binary form must reproduce the above copyright notice, 21 | * this list of conditions and the following disclaimer in the documentation 22 | * and/or other materials provided with the distribution. 23 | * 3. Neither the name of STMicroelectronics nor the names of other 24 | * contributors to this software may be used to endorse or promote products 25 | * derived from this software without specific written permission. 26 | * 4. This software, including modifications and/or derivative works of this 27 | * software, must execute solely and exclusively on microcontroller or 28 | * microprocessor devices manufactured by or for STMicroelectronics. 29 | * 5. Redistribution and use of this software other than as permitted under 30 | * this license is void and will automatically terminate your rights under 31 | * this license. 32 | * 33 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 34 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 36 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 37 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 38 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 39 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 41 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 42 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 43 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 44 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 | * 46 | ****************************************************************************** 47 | */ 48 | 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | 51 | #ifndef __USBD_STORAGE_IF_H_ 52 | #define __USBD_STORAGE_IF_H_ 53 | 54 | #include "usbd_msc.h" 55 | 56 | #define FATBytesPerSec MSC_MEDIA_PACKET 57 | 58 | #define FATFileNameSize 11 59 | #define FATDirSize 47 60 | #define FATBootSize 62 61 | #define FATTableSize 4 62 | 63 | 64 | typedef struct 65 | { 66 | uint8_t DIR_Name[11]; // File Name 67 | uint8_t DIR_Attr; // File Attribute 68 | uint8_t DIR_NTRes; // Reserved 69 | uint8_t DIR_CreateTime_Tenth; // Component of the file creation time 70 | uint16_t DIR_CreateTime; // Component of the file creation time 71 | uint16_t DIR_CreateDate; // Component of the file creation date 72 | uint16_t DIR_LastAccessDate; // Last Access date 73 | uint16_t DIR_ClusHigh; // High word of first data cluster 74 | uint16_t DIR_WriteTime; // Last modification write time 75 | uint16_t DIR_WriteDate; // Last modification write date 76 | uint16_t DIR_ClusLow; // Low word of first data cluster 77 | uint32_t DIR_FileSize; // Filesize 78 | } __attribute__((packed)) FAT_DIR_t; 79 | 80 | #endif /* __USBD_STORAGE_IF_H */ 81 | 82 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usb_msc_device.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v2.0_Cube 5 | * @brief : This file implements the USB Device 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2018 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | 52 | #include "usb_msc_device.h" 53 | 54 | #include "stm32f1xx.h" 55 | #include "stm32f1xx_hal.h" 56 | 57 | #include "usbd_def.h" 58 | #include "usbd_core.h" 59 | #include "usbd_msc.h" 60 | 61 | extern USBD_DescriptorsTypeDef MSC_Desc; 62 | extern USBD_StorageTypeDef USBD_Storage_Interface_fops_FS; 63 | 64 | /* USB Device Core handle declaration */ 65 | static USBD_HandleTypeDef hUsbMscDeviceFS; 66 | 67 | /* init function */ 68 | void App_msc_Init(void) 69 | { 70 | /* Init Device Library,Add Supported Class and Start the library*/ 71 | USBD_Init(&hUsbMscDeviceFS, &MSC_Desc, DEVICE_FS); 72 | 73 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)hUsbMscDeviceFS.pData , MSC_EPIN_ADDR , PCD_SNG_BUF, 0x98); 74 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)hUsbMscDeviceFS.pData , MSC_EPOUT_ADDR , PCD_SNG_BUF, 0xD8); 75 | 76 | USBD_RegisterClass(&hUsbMscDeviceFS, &USBD_MSC); 77 | 78 | USBD_MSC_RegisterStorage(&hUsbMscDeviceFS, &USBD_Storage_Interface_fops_FS); 79 | 80 | USBD_Start(&hUsbMscDeviceFS); 81 | 82 | } 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 92 | -------------------------------------------------------------------------------- /app/blackpill/HID/usbd_hid.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_hid.h 4 | * @author MCD Application Team 5 | * @version V2.4.1 6 | * @date 19-June-2015 7 | * @brief Header file for the usbd_hid_core.c file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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_HID_H 30 | #define __USB_HID_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_ioreq.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_HID 44 | * @brief This file is the Header file for usbd_hid.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup USBD_HID_Exported_Defines 50 | * @{ 51 | */ 52 | #define HID_EPIN_ADDR 0x81 53 | #define HID_EPIN_SIZE 0x08 54 | 55 | #define USB_HID_CONFIG_DESC_SIZ 34 56 | #define USB_HID_DESC_SIZ 9 57 | #define HID_KEYBOARD_REPORT_DESC_SIZE 63 58 | 59 | #define HID_DESCRIPTOR_TYPE 0x21 60 | #define HID_REPORT_DESC 0x22 61 | 62 | #define HID_HS_BINTERVAL 0x07 63 | #define HID_FS_BINTERVAL 0x0A 64 | #define HID_POLLING_INTERVAL 0x0A 65 | 66 | #define HID_REQ_SET_PROTOCOL 0x0B 67 | #define HID_REQ_GET_PROTOCOL 0x03 68 | 69 | #define HID_REQ_SET_IDLE 0x0A 70 | #define HID_REQ_GET_IDLE 0x02 71 | 72 | #define HID_REQ_SET_REPORT 0x09 73 | #define HID_REQ_GET_REPORT 0x01 74 | /** 75 | * @} 76 | */ 77 | 78 | 79 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 80 | * @{ 81 | */ 82 | typedef enum 83 | { 84 | HID_IDLE = 0, 85 | HID_BUSY, 86 | } 87 | HID_StateTypeDef; 88 | 89 | 90 | typedef struct 91 | { 92 | uint32_t Protocol; 93 | uint32_t IdleState; 94 | uint32_t AltSetting; 95 | HID_StateTypeDef state; 96 | uint8_t ledState; 97 | } 98 | USBD_HID_HandleTypeDef; 99 | /** 100 | * @} 101 | */ 102 | typedef void (*USBD_HID_LedStateCallback)(uint8_t ledState); 103 | 104 | 105 | 106 | /** @defgroup USBD_CORE_Exported_Macros 107 | * @{ 108 | */ 109 | 110 | /** 111 | * @} 112 | */ 113 | 114 | /** @defgroup USBD_CORE_Exported_Variables 115 | * @{ 116 | */ 117 | 118 | extern USBD_ClassTypeDef USBD_HID; 119 | #define USBD_HID_CLASS &USBD_HID 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup USB_CORE_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void USBD_HID_SetLedStateCallback( USBD_HID_LedStateCallback callback ); 130 | 131 | uint8_t USBD_HID_SendReport (USBD_HandleTypeDef *pdev, 132 | uint8_t *report, 133 | uint16_t len); 134 | 135 | uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev); 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #endif /* __USB_HID_H */ 146 | /** 147 | * @} 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 155 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header for the usbd_msc.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_MSC_H 30 | #define __USBD_MSC_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_msc_bot.h" 38 | #include "usbd_msc_scsi.h" 39 | #include "usbd_ioreq.h" 40 | 41 | /** @addtogroup USBD_MSC_BOT 42 | * @{ 43 | */ 44 | 45 | /** @defgroup USBD_MSC 46 | * @brief This file is the Header file for usbd_msc.c 47 | * @{ 48 | */ 49 | 50 | 51 | /** @defgroup USBD_BOT_Exported_Defines 52 | * @{ 53 | */ 54 | #define MSC_MAX_FS_PACKET 0x40 55 | #define MSC_MAX_HS_PACKET 0x200 56 | 57 | #define BOT_GET_MAX_LUN 0xFE 58 | #define BOT_RESET 0xFF 59 | #define USB_MSC_CONFIG_DESC_SIZ 32 60 | 61 | 62 | #define MSC_EPIN_ADDR 0x81 63 | #define MSC_EPOUT_ADDR 0x01 64 | 65 | 66 | #define MSC_MEDIA_PACKET 1024 67 | /** 68 | * @} 69 | */ 70 | 71 | /** @defgroup USB_CORE_Exported_Types 72 | * @{ 73 | */ 74 | typedef struct _USBD_STORAGE 75 | { 76 | int8_t (* Init) (uint8_t lun); 77 | int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); 78 | int8_t (* IsReady) (uint8_t lun); 79 | int8_t (* IsWriteProtected) (uint8_t lun); 80 | int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 81 | int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); 82 | int8_t (* GetMaxLun)(void); 83 | int8_t *pInquiry; 84 | 85 | }USBD_StorageTypeDef; 86 | 87 | 88 | typedef struct 89 | { 90 | uint32_t max_lun; 91 | uint32_t interface; 92 | uint8_t bot_state; 93 | uint8_t bot_status; 94 | uint16_t bot_data_length; 95 | uint8_t bot_data[MSC_MEDIA_PACKET]; 96 | USBD_MSC_BOT_CBWTypeDef cbw; 97 | USBD_MSC_BOT_CSWTypeDef csw; 98 | 99 | USBD_SCSI_SenseTypeDef scsi_sense [SENSE_LIST_DEEPTH]; 100 | uint8_t scsi_sense_head; 101 | uint8_t scsi_sense_tail; 102 | 103 | uint16_t scsi_blk_size; 104 | uint32_t scsi_blk_nbr; 105 | 106 | uint32_t scsi_blk_addr; 107 | uint32_t scsi_blk_len; 108 | } 109 | USBD_MSC_BOT_HandleTypeDef; 110 | 111 | /* Structure for MSC process */ 112 | extern USBD_ClassTypeDef USBD_MSC; 113 | #define USBD_MSC_CLASS &USBD_MSC 114 | 115 | uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, 116 | USBD_StorageTypeDef *fops); 117 | /** 118 | * @} 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* __USBD_MSC_H */ 130 | /** 131 | * @} 132 | */ 133 | 134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 135 | -------------------------------------------------------------------------------- /app/DebugCliTask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * DebugCliTask.c 3 | * 4 | * Created on: Feb 9, 2019 5 | * Author: maanu 6 | */ 7 | 8 | #include "stdio.h" 9 | #include "stdlib.h" 10 | 11 | #include "usbd_hid.h" 12 | 13 | #include "Kernel.h" 14 | 15 | #define MAX_CMD_LEN 16 16 | 17 | typedef void (*CmdFunc_t)(char* param); 18 | 19 | typedef struct cmdTable 20 | { 21 | uint8_t cmdLen; 22 | char* cmd; 23 | char* desc; 24 | CmdFunc_t func; 25 | } CmdTable_t; 26 | 27 | static void HandleDebugCommand(void); 28 | 29 | static void HandleCmdHelp(char* param); 30 | static void HandleHid(char* param); 31 | static void HandleReadMem(char* param); 32 | static void StartHid(char* param); 33 | static void StopHid(char* param); 34 | 35 | static CmdTable_t sCmdTable[] = 36 | { 37 | {4, "help", "show this information", HandleCmdHelp}, 38 | {3, "hid", "send hid keyboard report", HandleHid}, 39 | {2, "RM", "Read memory", HandleReadMem}, 40 | {5, "start", "Just send report", StartHid}, 41 | {4, "stop", "Stop report", StopHid}, 42 | {0, NULL,NULL,NULL} 43 | }; 44 | 45 | void Debug_cli_task(void) 46 | { 47 | DBG_PRINT("Debug_cli_task....\n"); 48 | 49 | while (true) 50 | { 51 | KernelEventFlag_t handle_event = Kernel_wait_events(KernelEventFlag_CmdIn); 52 | if (handle_event == KernelEventFlag_CmdIn) 53 | { 54 | HandleDebugCommand(); 55 | } 56 | Kernel_yield(); 57 | } 58 | } 59 | 60 | static void HandleDebugCommand(void) 61 | { 62 | char cmdStr[MAX_CMD_LEN] = {0}; 63 | char ch; 64 | uint32_t i; 65 | bool isLenExceed = true; 66 | 67 | for(i = 0 ; i < (MAX_CMD_LEN - 1) ; i++) 68 | { 69 | Kernel_recv_msg(KernelMsgQ_DebugCmd, &ch, 1); 70 | 71 | cmdStr[i] = ch; 72 | 73 | if (ch == '\0') 74 | { 75 | isLenExceed = false; 76 | break; 77 | } 78 | } 79 | 80 | if (isLenExceed) 81 | { 82 | // flush msgQ 83 | do 84 | { 85 | Kernel_recv_msg(KernelMsgQ_DebugCmd, &ch, 1); 86 | } while (ch != '\0'); 87 | } 88 | 89 | uint32_t param_start_pos = memfind((uint8_t*)cmdStr, ' ', i); 90 | 91 | // split cmd and param 92 | char* param = NULL; 93 | if (param_start_pos != (i + 1)) 94 | { 95 | *(cmdStr + param_start_pos) = '\0'; 96 | param = (cmdStr + param_start_pos + 1); 97 | } 98 | 99 | CmdTable_t* pCmdTblRow = sCmdTable; 100 | while(pCmdTblRow->cmdLen != 0) 101 | { 102 | if (memncmp((uint8_t*)pCmdTblRow->cmd, (uint8_t*)cmdStr, pCmdTblRow->cmdLen)) 103 | { 104 | pCmdTblRow->func(param); 105 | break; 106 | } 107 | pCmdTblRow++; 108 | } 109 | } 110 | 111 | static void HandleCmdHelp(char* param) 112 | { 113 | CmdTable_t* pCmdTblRow = sCmdTable; 114 | while(pCmdTblRow->cmdLen != 0) 115 | { 116 | DBG_PRINT("%s %s\n", pCmdTblRow->cmd, pCmdTblRow->desc); 117 | pCmdTblRow++; 118 | } 119 | } 120 | 121 | static void HandleHid(char* param) 122 | { 123 | uint8_t hid_key_report[8] = {0}; 124 | 125 | if (param != NULL) 126 | { 127 | hid_key_report[0] = 0x02; // shift 128 | } 129 | hid_key_report[2] = 0x11; // 'n' 130 | hid_key_report[3] = 0x1b; // 'x' 131 | Kernel_send_msg(KernelMsgQ_D2hData, hid_key_report, 8); 132 | Kernel_send_events(KernelEventFlag_SendD2H); 133 | 134 | Kernel_yield(); 135 | USBD_Delay(200); 136 | 137 | hid_key_report[0] = 0; 138 | hid_key_report[2] = 0; // clear 139 | hid_key_report[3] = 0; // clear 140 | Kernel_send_msg(KernelMsgQ_D2hData, hid_key_report, 8); 141 | Kernel_send_events(KernelEventFlag_SendD2H); 142 | } 143 | 144 | static void StartHid(char* param) 145 | { 146 | uint8_t hid_key_report[8] = {0}; 147 | hid_key_report[2] = 0x11; // 'n' 148 | hid_key_report[3] = 0x1b; // 'x' 149 | Kernel_send_msg(KernelMsgQ_D2hData, hid_key_report, 8); 150 | Kernel_send_events(KernelEventFlag_SendD2H); 151 | } 152 | 153 | static void StopHid(char* param) 154 | { 155 | uint8_t hid_key_report[8] = {0}; 156 | hid_key_report[0] = 0; 157 | hid_key_report[2] = 0; // clear 158 | hid_key_report[3] = 0; // clear 159 | Kernel_send_msg(KernelMsgQ_D2hData, hid_key_report, 8); 160 | Kernel_send_events(KernelEventFlag_SendD2H); 161 | } 162 | 163 | static void HandleReadMem(char* param) 164 | { 165 | if (param == NULL) 166 | { 167 | DBG_PRINT("No Param\n"); 168 | return; 169 | } 170 | 171 | uint32_t* addr = (uint32_t*)htou(param, strncnt(param, 8)); 172 | uint32_t data = *addr; 173 | 174 | DBG_PRINT("[%x] %x\n", addr, data); 175 | } 176 | -------------------------------------------------------------------------------- /app/blackpill/HID/usb_hid_keyboard.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : USB_DEVICE 4 | * @version : v2.0_Cube 5 | * @brief : This file implements the USB Device 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2017 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | 50 | /* Includes ------------------------------------------------------------------*/ 51 | 52 | #include "usb_hid_keyboard.h" 53 | 54 | #include "usbd_core.h" 55 | #include "usbd_hid.h" 56 | #include "usbd_hid_desc.h" 57 | 58 | extern USBD_DescriptorsTypeDef HID_Desc; 59 | 60 | /* USB Device Core handle declaration */ 61 | static USBD_HandleTypeDef hUsbHidDeviceFS; 62 | 63 | /* init function */ 64 | void App_hid_Init(void) 65 | { 66 | /* Init Device Library,Add Supported Class and Start the library*/ 67 | USBD_Init(&hUsbHidDeviceFS, &HID_Desc, DEVICE_FS); 68 | 69 | HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)hUsbHidDeviceFS.pData , HID_EPIN_ADDR , PCD_SNG_BUF, 0x100); 70 | 71 | USBD_RegisterClass(&hUsbHidDeviceFS, &USBD_HID); 72 | 73 | USBD_Start(&hUsbHidDeviceFS); 74 | 75 | } 76 | 77 | void App_hid_send(const void *data,const size_t size) 78 | { 79 | /* 80 | DBG_PRINT("Sending: "); 81 | for (int i=0; i
© COPYRIGHT(c) 2016 STMicroelectronics
12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ 39 | #ifndef __STM32F1xx_HAL_PCD_EX_H 40 | #define __STM32F1xx_HAL_PCD_EX_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #if defined(STM32F102x6) || defined(STM32F102xB) || \ 47 | defined(STM32F103x6) || defined(STM32F103xB) || \ 48 | defined(STM32F103xE) || defined(STM32F103xG) || \ 49 | defined(STM32F105xC) || defined(STM32F107xC) 50 | 51 | /* Includes ------------------------------------------------------------------*/ 52 | #include "stm32f1xx_hal_def.h" 53 | 54 | /** @addtogroup STM32F1xx_HAL_Driver 55 | * @{ 56 | */ 57 | 58 | /** @addtogroup PCDEx 59 | * @{ 60 | */ 61 | 62 | /* Exported types ------------------------------------------------------------*/ 63 | /* Exported constants --------------------------------------------------------*/ 64 | /* Exported macros -----------------------------------------------------------*/ 65 | /* Exported functions --------------------------------------------------------*/ 66 | /** @addtogroup PCDEx_Exported_Functions PCDEx Exported Functions 67 | * @{ 68 | */ 69 | /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions 70 | * @{ 71 | */ 72 | #if defined (USB_OTG_FS) 73 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); 74 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); 75 | #endif /* USB_OTG_FS */ 76 | 77 | #if defined (USB) 78 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, 79 | uint16_t ep_addr, 80 | uint16_t ep_kind, 81 | uint32_t pmaadress); 82 | #endif /* USB */ 83 | /** 84 | * @} 85 | */ 86 | 87 | /** @addtogroup PCDEx_Exported_Functions_Group2 Peripheral State functions 88 | * @{ 89 | */ 90 | void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); 91 | /** 92 | * @} 93 | */ 94 | /** 95 | * @} 96 | */ 97 | /** 98 | * @} 99 | */ 100 | 101 | /** 102 | * @} 103 | */ 104 | #endif /* STM32F102x6 || STM32F102xB || */ 105 | /* STM32F103x6 || STM32F103xB || */ 106 | /* STM32F103xE || STM32F103xG || */ 107 | /* STM32F105xC || STM32F107xC */ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | 114 | #endif /* __STM32F1xx_HAL_PCD_EX_H */ 115 | 116 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 117 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc_bot.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_bot.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header for the usbd_msc_bot.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_MSC_BOT_H 30 | #define __USBD_MSC_BOT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_core.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup MSC_BOT 44 | * @brief This file is the Header file for usbd_msc_bot.c 45 | * @{ 46 | */ 47 | 48 | 49 | /** @defgroup USBD_CORE_Exported_Defines 50 | * @{ 51 | */ 52 | #define USBD_BOT_IDLE 0 /* Idle state */ 53 | #define USBD_BOT_DATA_OUT 1 /* Data Out state */ 54 | #define USBD_BOT_DATA_IN 2 /* Data In state */ 55 | #define USBD_BOT_LAST_DATA_IN 3 /* Last Data In Last */ 56 | #define USBD_BOT_SEND_DATA 4 /* Send Immediate data */ 57 | #define USBD_BOT_NO_DATA 5 /* No data Stage */ 58 | 59 | #define USBD_BOT_CBW_SIGNATURE 0x43425355 60 | #define USBD_BOT_CSW_SIGNATURE 0x53425355 61 | #define USBD_BOT_CBW_LENGTH 31 62 | #define USBD_BOT_CSW_LENGTH 13 63 | #define USBD_BOT_MAX_DATA 256 64 | 65 | /* CSW Status Definitions */ 66 | #define USBD_CSW_CMD_PASSED 0x00 67 | #define USBD_CSW_CMD_FAILED 0x01 68 | #define USBD_CSW_PHASE_ERROR 0x02 69 | 70 | /* BOT Status */ 71 | #define USBD_BOT_STATUS_NORMAL 0 72 | #define USBD_BOT_STATUS_RECOVERY 1 73 | #define USBD_BOT_STATUS_ERROR 2 74 | 75 | 76 | #define USBD_DIR_IN 0 77 | #define USBD_DIR_OUT 1 78 | #define USBD_BOTH_DIR 2 79 | 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup MSC_CORE_Private_TypesDefinitions 85 | * @{ 86 | */ 87 | 88 | typedef struct 89 | { 90 | uint32_t dSignature; 91 | uint32_t dTag; 92 | uint32_t dDataLength; 93 | uint8_t bmFlags; 94 | uint8_t bLUN; 95 | uint8_t bCBLength; 96 | uint8_t CB[16]; 97 | uint8_t ReservedForAlign; 98 | } 99 | USBD_MSC_BOT_CBWTypeDef; 100 | 101 | 102 | typedef struct 103 | { 104 | uint32_t dSignature; 105 | uint32_t dTag; 106 | uint32_t dDataResidue; 107 | uint8_t bStatus; 108 | uint8_t ReservedForAlign[3]; 109 | } 110 | USBD_MSC_BOT_CSWTypeDef; 111 | 112 | /** 113 | * @} 114 | */ 115 | 116 | 117 | /** @defgroup USBD_CORE_Exported_Types 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | /** @defgroup USBD_CORE_Exported_FunctionsPrototypes 125 | * @{ 126 | */ 127 | void MSC_BOT_Init (USBD_HandleTypeDef *pdev); 128 | void MSC_BOT_Reset (USBD_HandleTypeDef *pdev); 129 | void MSC_BOT_DeInit (USBD_HandleTypeDef *pdev); 130 | void MSC_BOT_DataIn (USBD_HandleTypeDef *pdev, 131 | uint8_t epnum); 132 | 133 | void MSC_BOT_DataOut (USBD_HandleTypeDef *pdev, 134 | uint8_t epnum); 135 | 136 | void MSC_BOT_SendCSW (USBD_HandleTypeDef *pdev, 137 | uint8_t CSW_Status); 138 | 139 | void MSC_BOT_CplClrFeature (USBD_HandleTypeDef *pdev, 140 | uint8_t epnum); 141 | /** 142 | * @} 143 | */ 144 | 145 | #ifdef __cplusplus 146 | } 147 | #endif 148 | 149 | #endif /* __USBD_MSC_BOT_H */ 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 158 | 159 | -------------------------------------------------------------------------------- /app/blackpill/Layout/gosupeek/Layout.c: -------------------------------------------------------------------------------- 1 | #include "KeyHw.h" 2 | #include "keymap.h" 3 | #include "Layout.h" 4 | 5 | #include "stm32f1xx_hal.h" 6 | 7 | /* Gosupeek Keylayout 8 | * COL (input) 9 | * +--------+----------------------------------------------------------------------------------------------+ 10 | * | Col# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 11 | * +--------+------+-------+-----+-----+-------+-----+------+-----+-----+-----+-----+------+-------+-------+ 12 | * |R# | | PA6 | PA7 | PB0 | PB1 | PB3 | PB4 | PB5 | PB6 | PB7 | PB8 | PB9 | PB13 | PB14 | PB15 | 13 | * +---+----+------+-------+-----+-----+-------+-----+------+-----+-----+-----+-----+------+-------+-------+ 14 | * | 0 |PA0 | | 15 | * | 1 |PA1 | | 16 | * ROW | 2 |PA2 | DEFAULT KEY MAP defined by Keymap.c | 17 | *(out) | 3 |PA3 | or User custom keymap | 18 | * | 4 |PA4 | | 19 | * | 5 |PA5 | | 20 | * +-- +---------------------------------------------------------------------------------------------------+ 21 | */ 22 | 23 | /* Extra Pin usage 24 | * PA9, PA10 - UART1 - Debug CLI 25 | * PA11, PA12 - USB 26 | * PB10, PB11 - UART3 - Bluetooth 27 | */ 28 | Keypin_t gRowPin[KEYMAP_ROW_NUM] = { 29 | {(uint32_t)GPIOA, GPIO_PIN_0}, 30 | {(uint32_t)GPIOA, GPIO_PIN_1}, 31 | {(uint32_t)GPIOA, GPIO_PIN_2}, 32 | {(uint32_t)GPIOA, GPIO_PIN_3}, 33 | {(uint32_t)GPIOA, GPIO_PIN_4}, 34 | {(uint32_t)GPIOA, GPIO_PIN_5} 35 | }; 36 | 37 | Keypin_t gColPin[KEYMAP_COL_NUM] = { 38 | {(uint32_t)GPIOA, GPIO_PIN_6}, {(uint32_t)GPIOA, GPIO_PIN_7}, 39 | {(uint32_t)GPIOB, GPIO_PIN_0}, {(uint32_t)GPIOB, GPIO_PIN_1}, 40 | {(uint32_t)GPIOB, GPIO_PIN_3}, {(uint32_t)GPIOB, GPIO_PIN_4}, {(uint32_t)GPIOB, GPIO_PIN_5}, {(uint32_t)GPIOB, GPIO_PIN_6}, {(uint32_t)GPIOB, GPIO_PIN_7}, {(uint32_t)GPIOB, GPIO_PIN_8}, {(uint32_t)GPIOB, GPIO_PIN_9}, 41 | {(uint32_t)GPIOB, GPIO_PIN_13}, {(uint32_t)GPIOB, GPIO_PIN_14}, {(uint32_t)GPIOB, GPIO_PIN_15} 42 | }; 43 | 44 | 45 | /* Default Keymap 46 | * COL (input) 47 | * +----+----------------------------------------------------------------------------------------------+ 48 | * |Col#| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 49 | * +----+------+-------+-----+-----+-------+-----+------+-----+-----+-----+-----+------+-------+-------+ 50 | * | 0 | ESC | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | back | 51 | * | 1 | Home | ~ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | + | 52 | * ROW | 2 | End | Tab | Q | W | E | R | T | Y | U | I | O | P | [ | ] | 53 | *(out) | 3 | Inst | Fn | A | S | D | F | G | H | J | K | L | ; | ' | Enter | 54 | * | 4 | PgUp | shift | Z | X | C | V | B | N | M | < | > | ? | shift | ↑ | 55 | * | 5 | PgDn | ctrl | Win | alt | space | alt | ctrl | ← | ↓ | → | \ | del | | | 56 | * +----+----------------------------------------------------------------------------------------------+ 57 | * 58 | */ 59 | uint8_t gKeymap_buffer_layer0[KEYMAP_ROW_NUM][KEYMAP_COL_NUM] = 60 | { /* Col#0 Col#1 Col#2 Col#3 Col#4 Col#5 Col#6 Col#7 Col#8 Col#9 Col#10 Col#11 Col#12 Col#13 */ 61 | /* Row#0 */ {kEsc, kF1, kF2, kF3, kF4, kF5, kF6, kF7, kF8, kF9, kF10, kF11, kF12, kBackspace}, 62 | /* Row#1 */ {kHome, kGrave, k1, k2, k3, k4, k5, k6, k7, k8, k9, k0, kMinus, kEqual}, 63 | /* Row#2 */ {kEnd, kTab, kQ, kW, kE, kR, kT, kY, kU, kI, kO, kP, kLeftbrace, kRightbrace}, 64 | /* Row#3 */ {kInsert, kFunction, kA, kS, kD, kF, kG, kH, kJ, kK, kL, kSemicolon, kApostrophe, kEnter}, 65 | /* Row#4 */ {kPageup, kLeftshift,kZ, kX, kC, kV, kB, kN, kM, kComma, kDot, kSlash, kRightshift, kUp}, 66 | /* Row#5 */ {kPagedown, kLeftctrl, kLeftmeta, kLeftalt, kSpace, kRightalt,kRightctrl,kLeft,kDown, kRight, kBackslash, kDelete, kNone, kNone} 67 | }; 68 | 69 | uint8_t gKeymap_buffer_layer1[KEYMAP_ROW_NUM][KEYMAP_COL_NUM] = 70 | { /* Col#0 Col#1 Col#2 Col#3 Col#4 Col#5 Col#6 Col#7 Col#8 Col#9 Col#10 Col#11 Col#12 Col#13 */ 71 | /* Row#0 */ {0}, 72 | /* Row#1 */ {0}, 73 | /* Row#2 */ {0}, 74 | /* Row#3 */ {0}, 75 | /* Row#4 */ {0}, 76 | /* Row#5 */ {0} 77 | }; 78 | 79 | void ChangeReportByLayout(uint8_t *report) 80 | { 81 | // Do Nothing 82 | return; 83 | } -------------------------------------------------------------------------------- /boot/blackpill/main.c: -------------------------------------------------------------------------------- 1 | #include "stdbool.h" 2 | #include "stdint.h" 3 | #include "stdio.h" 4 | #include "stdlib.h" 5 | 6 | #include "stm32f1xx_hal.h" 7 | 8 | #include "usb_hid_keyboard.h" 9 | #include "usb_msc_device.h" 10 | 11 | #include "HalGpio.h" 12 | #include "HalUart.h" 13 | 14 | #include "KeyHw.h" 15 | 16 | #include "Kernel.h" 17 | #include "MemoryMap.h" 18 | 19 | #define SYSTEM_US_TICKS (SystemCoreClock / 1000000) // cycles per microsecond 20 | 21 | /* Private function prototypes -----------------------------------------------*/ 22 | static void SystemClock_Config(void); 23 | 24 | #ifdef LOADER 25 | static bool CheckBootMode(void) 26 | { 27 | // get HW (0,0) key pressed during keyboard power-up time. 28 | // while user presses HW (0,0) key, FW enters a keymap download mode or FW update mode. 29 | // no matter what key code mapped into the (0,0). It just check matrix (0,0). 30 | return KeyHw_IsPressed(0, 0); 31 | } 32 | 33 | static void Jump(uint32_t address) 34 | { 35 | typedef void (*pFunction)(void); 36 | 37 | pFunction Jump_To_Application; 38 | 39 | // variable that will be loaded with the start address of the application 40 | uint32_t* JumpAddress; 41 | const uint32_t* ApplicationAddress = (uint32_t *)address; 42 | 43 | // get jump address from application vector table 44 | JumpAddress = (uint32_t *)ApplicationAddress[1]; 45 | 46 | // load this address into function pointer 47 | Jump_To_Application = (pFunction)JumpAddress; 48 | 49 | // Disable all interrupts 50 | for (int i = 0; i < 8; i++) { 51 | NVIC->ICER[i] = NVIC->IABR[i]; 52 | } 53 | 54 | // Set interrupt vector table 55 | SCB->VTOR = address; /* Vector Table Relocation in Internal FLASH. */ 56 | 57 | // Set stack pointer as in application's vector table 58 | __set_MSP((uint32_t)(ApplicationAddress[0])); 59 | 60 | // Go 61 | Jump_To_Application(); 62 | } 63 | 64 | #else 65 | 66 | static void Kernel_Init(void) 67 | { 68 | extern void Polling_task(); 69 | extern void Host_comm_task(); 70 | extern void Debug_cli_task(); 71 | extern void Keymap_dnldr_task(); 72 | 73 | uint32_t taskId; 74 | 75 | Kernel_task_init(); 76 | 77 | taskId = Kernel_task_create(Polling_task); 78 | if (NOT_ENOUGH_TASK_NUM == taskId) 79 | { 80 | DBG_PRINT("Polling_task creation fail\n"); 81 | } 82 | 83 | taskId = Kernel_task_create(Host_comm_task); 84 | if (NOT_ENOUGH_TASK_NUM == taskId) 85 | { 86 | DBG_PRINT("Host_comm_task creation fail\n"); 87 | } 88 | 89 | #if (DEBUG_PRINT == 1) 90 | taskId = Kernel_task_create(Debug_cli_task); 91 | if (NOT_ENOUGH_TASK_NUM == taskId) 92 | { 93 | DBG_PRINT("Debug_cli_task creation fail\n"); 94 | } 95 | #endif 96 | } 97 | #endif 98 | 99 | int main(void) 100 | { 101 | HAL_Init(); 102 | SystemClock_Config(); 103 | 104 | Hal_gpio_init(); 105 | 106 | #if (DEBUG_PRINT == 1) 107 | Hal_uart_init(); 108 | #endif 109 | 110 | #ifdef LOADER 111 | if (CheckBootMode()) 112 | { 113 | DBG_PRINT("BootLoader..\n"); 114 | App_msc_Init(); 115 | } 116 | else 117 | { 118 | DBG_PRINT("Jump to the MainFW..\n"); 119 | Jump(MAIN_FW_BADDR); 120 | } 121 | #else 122 | App_hid_Init(); 123 | 124 | while (USBD_HID_Is_Configured() != true) 125 | { 126 | DBG_PRINT("Waiting for USBHID configuration\n"); 127 | USBD_Delay(1000); 128 | } 129 | 130 | Kernel_Init(); 131 | DBG_PRINT("Navilos Start..\n"); 132 | Kernel_start(); 133 | #endif 134 | 135 | while (1) { } 136 | } 137 | 138 | /** System Clock Configuration 139 | */ 140 | static void SystemClock_Config(void) 141 | { 142 | RCC_OscInitTypeDef RCC_OscInitStruct; 143 | RCC_ClkInitTypeDef RCC_ClkInitStruct; 144 | RCC_PeriphCLKInitTypeDef PeriphClkInit; 145 | 146 | /**Initializes the CPU, AHB and APB busses clocks 147 | */ 148 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 149 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 150 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 151 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 152 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 153 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 154 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6; 155 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 156 | { 157 | halt(__FILE__, __LINE__); 158 | } 159 | 160 | /**Initializes the CPU, AHB and APB busses clocks 161 | */ 162 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 163 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 164 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 165 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 166 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 167 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV4; 168 | 169 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) 170 | { 171 | halt(__FILE__, __LINE__); 172 | } 173 | 174 | PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; 175 | PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL; 176 | if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) 177 | { 178 | halt(__FILE__, __LINE__); 179 | } 180 | 181 | /**Configure the Systick interrupt time 182 | */ 183 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); 184 | 185 | /**Configure the Systick 186 | */ 187 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); 188 | 189 | /* SysTick_IRQn interrupt configuration */ 190 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 191 | } 192 | 193 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f1xx_hal_gpio_ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_hal_gpio_ex.c 4 | * @author MCD Application Team 5 | * @version V1.1.1 6 | * @date 12-May-2017 7 | * @brief GPIO Extension HAL module driver. 8 | * This file provides firmware functions to manage the following 9 | * functionalities of the General Purpose Input/Output (GPIO) extension peripheral. 10 | * + Extended features functions 11 | * 12 | @verbatim 13 | ============================================================================== 14 | ##### GPIO Peripheral extension features ##### 15 | ============================================================================== 16 | [..] GPIO module on STM32F1 family, manage also the AFIO register: 17 | (+) Possibility to use the EVENTOUT Cortex feature 18 | 19 | ##### How to use this driver ##### 20 | ============================================================================== 21 | [..] This driver provides functions to use EVENTOUT Cortex feature 22 | (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 23 | (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 24 | (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 25 | 26 | @endverbatim 27 | ****************************************************************************** 28 | * @attention 29 | * 30 | *

© COPYRIGHT(c) 2016 STMicroelectronics

31 | * 32 | * Redistribution and use in source and binary forms, with or without modification, 33 | * are permitted provided that the following conditions are met: 34 | * 1. Redistributions of source code must retain the above copyright notice, 35 | * this list of conditions and the following disclaimer. 36 | * 2. Redistributions in binary form must reproduce the above copyright notice, 37 | * this list of conditions and the following disclaimer in the documentation 38 | * and/or other materials provided with the distribution. 39 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 40 | * may be used to endorse or promote products derived from this software 41 | * without specific prior written permission. 42 | * 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 44 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 46 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 49 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 50 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 51 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 53 | * 54 | ****************************************************************************** 55 | */ 56 | 57 | /* Includes ------------------------------------------------------------------*/ 58 | #include "stm32f1xx_hal.h" 59 | 60 | /** @addtogroup STM32F1xx_HAL_Driver 61 | * @{ 62 | */ 63 | 64 | /** @defgroup GPIOEx GPIOEx 65 | * @brief GPIO HAL module driver 66 | * @{ 67 | */ 68 | 69 | #ifdef HAL_GPIO_MODULE_ENABLED 70 | 71 | /** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions 72 | * @{ 73 | */ 74 | 75 | /** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions 76 | * @brief Extended features functions 77 | * 78 | @verbatim 79 | ============================================================================== 80 | ##### Extended features functions ##### 81 | ============================================================================== 82 | [..] This section provides functions allowing to: 83 | (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() 84 | (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() 85 | (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 86 | 87 | @endverbatim 88 | * @{ 89 | */ 90 | 91 | /** 92 | * @brief Configures the port and pin on which the EVENTOUT Cortex signal will be connected. 93 | * @param GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal. 94 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT. 95 | * @param GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal. 96 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN. 97 | * @retval None 98 | */ 99 | void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) 100 | { 101 | /* Verify the parameters */ 102 | assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource)); 103 | assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource)); 104 | 105 | /* Apply the new configuration */ 106 | MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT)|(AFIO_EVCR_PIN), (GPIO_PortSource)|(GPIO_PinSource)); 107 | } 108 | 109 | /** 110 | * @brief Enables the Event Output. 111 | * @retval None 112 | */ 113 | void HAL_GPIOEx_EnableEventout(void) 114 | { 115 | SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 116 | } 117 | 118 | /** 119 | * @brief Disables the Event Output. 120 | * @retval None 121 | */ 122 | void HAL_GPIOEx_DisableEventout(void) 123 | { 124 | CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); 125 | } 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | #endif /* HAL_GPIO_MODULE_ENABLED */ 136 | 137 | /** 138 | * @} 139 | */ 140 | 141 | /** 142 | * @} 143 | */ 144 | 145 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 146 | -------------------------------------------------------------------------------- /app/blackpill/USB/usbd_core.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_core.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header file for usbd_core.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_CORE_H 30 | #define __USBD_CORE_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_conf.h" 38 | #include "usbd_def.h" 39 | #include "usbd_ioreq.h" 40 | #include "usbd_ctlreq.h" 41 | 42 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 43 | * @{ 44 | */ 45 | 46 | /** @defgroup USBD_CORE 47 | * @brief This file is the Header file for usbd_core.c file 48 | * @{ 49 | */ 50 | 51 | 52 | /** @defgroup USBD_CORE_Exported_Defines 53 | * @{ 54 | */ 55 | 56 | /** 57 | * @} 58 | */ 59 | 60 | 61 | /** @defgroup USBD_CORE_Exported_TypesDefinitions 62 | * @{ 63 | */ 64 | 65 | 66 | /** 67 | * @} 68 | */ 69 | 70 | 71 | 72 | /** @defgroup USBD_CORE_Exported_Macros 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup USBD_CORE_Exported_Variables 81 | * @{ 82 | */ 83 | #define USBD_SOF USBD_LL_SOF 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype 89 | * @{ 90 | */ 91 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id); 92 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev); 93 | USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev); 94 | USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev); 95 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass); 96 | 97 | USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev); 98 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 99 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx); 100 | 101 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup); 102 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 103 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata); 104 | 105 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev); 106 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed); 107 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev); 108 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev); 109 | 110 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev); 111 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 112 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum); 113 | 114 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev); 115 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev); 116 | 117 | /* USBD Low Level Driver */ 118 | USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev); 119 | USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev); 120 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev); 121 | USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev); 122 | USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, 123 | uint8_t ep_addr, 124 | uint8_t ep_type, 125 | uint16_t ep_mps); 126 | 127 | USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 128 | USBD_StatusTypeDef USBD_LL_FlushEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 129 | USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 130 | USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 131 | uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 132 | USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr); 133 | USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, 134 | uint8_t ep_addr, 135 | uint8_t *pbuf, 136 | uint16_t size); 137 | 138 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, 139 | uint8_t ep_addr, 140 | uint8_t *pbuf, 141 | uint16_t size); 142 | 143 | uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr); 144 | void USBD_LL_Delay (uint32_t Delay); 145 | 146 | /** 147 | * @} 148 | */ 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | 154 | #endif /* __USBD_CORE_H */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** 161 | * @} 162 | */ 163 | 164 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /app/blackpill/USB/usbd_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file : usbd_conf.h 4 | * @version : v2.0_Cube 5 | * @brief : Header for usbd_conf file. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2017 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Define to prevent recursive inclusion -------------------------------------*/ 50 | #ifndef __USBD_CONF__H__ 51 | #define __USBD_CONF__H__ 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | /* Includes ------------------------------------------------------------------*/ 56 | #include 57 | #include 58 | #include 59 | #include "stm32f1xx.h" 60 | #include "stm32f1xx_hal.h" 61 | #include "usbd_def.h" 62 | 63 | /** @addtogroup USBD_OTG_DRIVER 64 | * @{ 65 | */ 66 | 67 | /** @defgroup USBD_CONF 68 | * @brief usb otg low level driver configuration file 69 | * @{ 70 | */ 71 | 72 | /** @defgroup USBD_CONF_Exported_Defines 73 | * @{ 74 | */ 75 | 76 | /*---------- -----------*/ 77 | #define USBD_MAX_NUM_INTERFACES 1 78 | /*---------- -----------*/ 79 | #define USBD_MAX_NUM_CONFIGURATION 1 80 | /*---------- -----------*/ 81 | #define USBD_MAX_STR_DESC_SIZ 512 82 | /*---------- -----------*/ 83 | #define USBD_SUPPORT_USER_STRING 0 84 | /*---------- -----------*/ 85 | #define USBD_DEBUG_LEVEL 0 86 | /*---------- -----------*/ 87 | #define USBD_SELF_POWERED 1 88 | /****************************************/ 89 | /* #define for FS and HS identification */ 90 | #define DEVICE_FS 0 91 | 92 | /** @defgroup USBD_Exported_Macros 93 | * @{ 94 | */ 95 | 96 | /* Memory management macros */ 97 | #define USBD_malloc (uint32_t *)USBD_static_malloc 98 | #define USBD_free USBD_static_free 99 | #define USBD_memset /* Not used */ 100 | #define USBD_memcpy /* Not used */ 101 | 102 | #define USBD_Delay HAL_Delay 103 | 104 | /* For footprint reasons and since only one allocation is handled in the HID class 105 | driver, the malloc/free is changed into a static allocation method */ 106 | void *USBD_static_malloc(uint32_t size); 107 | void USBD_static_free(void *p); 108 | 109 | /* DEBUG macros */ 110 | #if (USBD_DEBUG_LEVEL > 0) 111 | #define USBD_UsrLog(...) printf(__VA_ARGS__);\ 112 | printf("\n"); 113 | #else 114 | #define USBD_UsrLog(...) 115 | #endif 116 | 117 | 118 | #if (USBD_DEBUG_LEVEL > 1) 119 | 120 | #define USBD_ErrLog(...) printf("ERROR: ") ;\ 121 | printf(__VA_ARGS__);\ 122 | printf("\n"); 123 | #else 124 | #define USBD_ErrLog(...) 125 | #endif 126 | 127 | 128 | #if (USBD_DEBUG_LEVEL > 2) 129 | #define USBD_DbgLog(...) printf("DEBUG : ") ;\ 130 | printf(__VA_ARGS__);\ 131 | printf("\n"); 132 | #else 133 | #define USBD_DbgLog(...) 134 | #endif 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup USBD_CONF_Exported_Types 147 | * @{ 148 | */ 149 | /** 150 | * @} 151 | */ 152 | 153 | /** @defgroup USBD_CONF_Exported_Macros 154 | * @{ 155 | */ 156 | /** 157 | * @} 158 | */ 159 | 160 | /** @defgroup USBD_CONF_Exported_Variables 161 | * @{ 162 | */ 163 | /** 164 | * @} 165 | */ 166 | 167 | /** @defgroup USBD_CONF_Exported_FunctionsPrototype 168 | * @{ 169 | */ 170 | /** 171 | * @} 172 | */ 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif /*__USBD_CONF__H__*/ 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | /** 184 | * @} 185 | */ 186 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 187 | 188 | -------------------------------------------------------------------------------- /app/blackpill/USB/usbd_ioreq.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_ioreq.c 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief This file provides the IO requests APIs for control endpoints. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 "usbd_ioreq.h" 30 | 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 32 | * @{ 33 | */ 34 | 35 | 36 | /** @defgroup USBD_IOREQ 37 | * @brief control I/O requests module 38 | * @{ 39 | */ 40 | 41 | /** @defgroup USBD_IOREQ_Private_TypesDefinitions 42 | * @{ 43 | */ 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @defgroup USBD_IOREQ_Private_Defines 50 | * @{ 51 | */ 52 | 53 | /** 54 | * @} 55 | */ 56 | 57 | 58 | /** @defgroup USBD_IOREQ_Private_Macros 59 | * @{ 60 | */ 61 | /** 62 | * @} 63 | */ 64 | 65 | 66 | /** @defgroup USBD_IOREQ_Private_Variables 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | 75 | /** @defgroup USBD_IOREQ_Private_FunctionPrototypes 76 | * @{ 77 | */ 78 | /** 79 | * @} 80 | */ 81 | 82 | 83 | /** @defgroup USBD_IOREQ_Private_Functions 84 | * @{ 85 | */ 86 | 87 | /** 88 | * @brief USBD_CtlSendData 89 | * send data on the ctl pipe 90 | * @param pdev: device instance 91 | * @param buff: pointer to data buffer 92 | * @param len: length of data to be sent 93 | * @retval status 94 | */ 95 | USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, 96 | uint8_t *pbuf, 97 | uint16_t len) 98 | { 99 | /* Set EP0 State */ 100 | pdev->ep0_state = USBD_EP0_DATA_IN; 101 | pdev->ep_in[0].total_length = len; 102 | pdev->ep_in[0].rem_length = len; 103 | /* Start the transfer */ 104 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 105 | 106 | return USBD_OK; 107 | } 108 | 109 | /** 110 | * @brief USBD_CtlContinueSendData 111 | * continue sending data on the ctl pipe 112 | * @param pdev: device instance 113 | * @param buff: pointer to data buffer 114 | * @param len: length of data to be sent 115 | * @retval status 116 | */ 117 | USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, 118 | uint8_t *pbuf, 119 | uint16_t len) 120 | { 121 | /* Start the next transfer */ 122 | USBD_LL_Transmit (pdev, 0x00, pbuf, len); 123 | 124 | return USBD_OK; 125 | } 126 | 127 | /** 128 | * @brief USBD_CtlPrepareRx 129 | * receive data on the ctl pipe 130 | * @param pdev: device instance 131 | * @param buff: pointer to data buffer 132 | * @param len: length of data to be received 133 | * @retval status 134 | */ 135 | USBD_StatusTypeDef USBD_CtlPrepareRx (USBD_HandleTypeDef *pdev, 136 | uint8_t *pbuf, 137 | uint16_t len) 138 | { 139 | /* Set EP0 State */ 140 | pdev->ep0_state = USBD_EP0_DATA_OUT; 141 | pdev->ep_out[0].total_length = len; 142 | pdev->ep_out[0].rem_length = len; 143 | /* Start the transfer */ 144 | USBD_LL_PrepareReceive (pdev, 145 | 0, 146 | pbuf, 147 | len); 148 | 149 | return USBD_OK; 150 | } 151 | 152 | /** 153 | * @brief USBD_CtlContinueRx 154 | * continue receive data on the ctl pipe 155 | * @param pdev: device instance 156 | * @param buff: pointer to data buffer 157 | * @param len: length of data to be received 158 | * @retval status 159 | */ 160 | USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, 161 | uint8_t *pbuf, 162 | uint16_t len) 163 | { 164 | 165 | USBD_LL_PrepareReceive (pdev, 166 | 0, 167 | pbuf, 168 | len); 169 | return USBD_OK; 170 | } 171 | /** 172 | * @brief USBD_CtlSendStatus 173 | * send zero lzngth packet on the ctl pipe 174 | * @param pdev: device instance 175 | * @retval status 176 | */ 177 | USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) 178 | { 179 | 180 | /* Set EP0 State */ 181 | pdev->ep0_state = USBD_EP0_STATUS_IN; 182 | 183 | /* Start the transfer */ 184 | USBD_LL_Transmit (pdev, 0x00, NULL, 0); 185 | 186 | return USBD_OK; 187 | } 188 | 189 | /** 190 | * @brief USBD_CtlReceiveStatus 191 | * receive zero lzngth packet on the ctl pipe 192 | * @param pdev: device instance 193 | * @retval status 194 | */ 195 | USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) 196 | { 197 | /* Set EP0 State */ 198 | pdev->ep0_state = USBD_EP0_STATUS_OUT; 199 | 200 | /* Start the transfer */ 201 | USBD_LL_PrepareReceive ( pdev, 202 | 0, 203 | NULL, 204 | 0); 205 | 206 | return USBD_OK; 207 | } 208 | 209 | 210 | /** 211 | * @brief USBD_GetRxCount 212 | * returns the received data length 213 | * @param pdev: device instance 214 | * @param ep_addr: endpoint address 215 | * @retval Rx Data blength 216 | */ 217 | uint16_t USBD_GetRxCount (USBD_HandleTypeDef *pdev , uint8_t ep_addr) 218 | { 219 | return USBD_LL_GetRxDataSize(pdev, ep_addr); 220 | } 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | 227 | /** 228 | * @} 229 | */ 230 | 231 | 232 | /** 233 | * @} 234 | */ 235 | 236 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 237 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f1xx_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f1xx_it.c 4 | * @brief Interrupt Service Routines. 5 | ****************************************************************************** 6 | * 7 | * COPYRIGHT(c) 2017 STMicroelectronics 8 | * 9 | * Redistribution and use in source and binary forms, with or without modification, 10 | * are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice, 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | ****************************************************************************** 32 | */ 33 | /* Includes ------------------------------------------------------------------*/ 34 | #include "stm32f1xx_hal.h" 35 | #include "stm32f1xx.h" 36 | #include "stm32f1xx_it.h" 37 | 38 | /* USER CODE BEGIN 0 */ 39 | 40 | /* USER CODE END 0 */ 41 | 42 | /* External variables --------------------------------------------------------*/ 43 | extern PCD_HandleTypeDef hpcd_USB_FS; 44 | 45 | /******************************************************************************/ 46 | /* Cortex-M3 Processor Interruption and Exception Handlers */ 47 | /******************************************************************************/ 48 | 49 | /** 50 | * @brief This function handles Non maskable interrupt. 51 | */ 52 | void NMI_Handler(void) 53 | { 54 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ 55 | 56 | /* USER CODE END NonMaskableInt_IRQn 0 */ 57 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ 58 | 59 | /* USER CODE END NonMaskableInt_IRQn 1 */ 60 | } 61 | 62 | /** 63 | * @brief This function handles Hard fault interrupt. 64 | */ 65 | void HardFault_Handler(void) 66 | { 67 | /* USER CODE BEGIN HardFault_IRQn 0 */ 68 | 69 | /* USER CODE END HardFault_IRQn 0 */ 70 | while (1) 71 | { 72 | } 73 | /* USER CODE BEGIN HardFault_IRQn 1 */ 74 | 75 | /* USER CODE END HardFault_IRQn 1 */ 76 | } 77 | 78 | /** 79 | * @brief This function handles Memory management fault. 80 | */ 81 | void MemManage_Handler(void) 82 | { 83 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */ 84 | 85 | /* USER CODE END MemoryManagement_IRQn 0 */ 86 | while (1) 87 | { 88 | } 89 | /* USER CODE BEGIN MemoryManagement_IRQn 1 */ 90 | 91 | /* USER CODE END MemoryManagement_IRQn 1 */ 92 | } 93 | 94 | /** 95 | * @brief This function handles Prefetch fault, memory access fault. 96 | */ 97 | void BusFault_Handler(void) 98 | { 99 | /* USER CODE BEGIN BusFault_IRQn 0 */ 100 | 101 | /* USER CODE END BusFault_IRQn 0 */ 102 | while (1) 103 | { 104 | } 105 | /* USER CODE BEGIN BusFault_IRQn 1 */ 106 | 107 | /* USER CODE END BusFault_IRQn 1 */ 108 | } 109 | 110 | /** 111 | * @brief This function handles Undefined instruction or illegal state. 112 | */ 113 | void UsageFault_Handler(void) 114 | { 115 | /* USER CODE BEGIN UsageFault_IRQn 0 */ 116 | 117 | /* USER CODE END UsageFault_IRQn 0 */ 118 | while (1) 119 | { 120 | } 121 | /* USER CODE BEGIN UsageFault_IRQn 1 */ 122 | 123 | /* USER CODE END UsageFault_IRQn 1 */ 124 | } 125 | 126 | /** 127 | * @brief This function handles System service call via SWI instruction. 128 | */ 129 | void SVC_Handler(void) 130 | { 131 | /* USER CODE BEGIN SVCall_IRQn 0 */ 132 | 133 | /* USER CODE END SVCall_IRQn 0 */ 134 | /* USER CODE BEGIN SVCall_IRQn 1 */ 135 | 136 | /* USER CODE END SVCall_IRQn 1 */ 137 | } 138 | 139 | /** 140 | * @brief This function handles Debug monitor. 141 | */ 142 | void DebugMon_Handler(void) 143 | { 144 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */ 145 | 146 | /* USER CODE END DebugMonitor_IRQn 0 */ 147 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */ 148 | 149 | /* USER CODE END DebugMonitor_IRQn 1 */ 150 | } 151 | 152 | /** 153 | * @brief This function handles Pendable request for system service. 154 | */ 155 | void PendSV_Handler(void) 156 | { 157 | /* USER CODE BEGIN PendSV_IRQn 0 */ 158 | 159 | /* USER CODE END PendSV_IRQn 0 */ 160 | /* USER CODE BEGIN PendSV_IRQn 1 */ 161 | 162 | /* USER CODE END PendSV_IRQn 1 */ 163 | } 164 | 165 | /** 166 | * @brief This function handles System tick timer. 167 | */ 168 | void SysTick_Handler(void) 169 | { 170 | /* USER CODE BEGIN SysTick_IRQn 0 */ 171 | 172 | /* USER CODE END SysTick_IRQn 0 */ 173 | HAL_IncTick(); 174 | HAL_SYSTICK_IRQHandler(); 175 | /* USER CODE BEGIN SysTick_IRQn 1 */ 176 | 177 | /* USER CODE END SysTick_IRQn 1 */ 178 | } 179 | 180 | /******************************************************************************/ 181 | /* STM32F1xx Peripheral Interrupt Handlers */ 182 | /* Add here the Interrupt Handlers for the used peripherals. */ 183 | /* For the available peripheral interrupt handler names, */ 184 | /* please refer to the startup file (startup_stm32f1xx.s). */ 185 | /******************************************************************************/ 186 | 187 | /** 188 | * @brief This function handles USB low priority or CAN RX0 interrupts. 189 | */ 190 | void USB_LP_CAN1_RX0_IRQHandler(void) 191 | { 192 | /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 0 */ 193 | 194 | /* USER CODE END USB_LP_CAN1_RX0_IRQn 0 */ 195 | HAL_PCD_IRQHandler(&hpcd_USB_FS); 196 | /* USER CODE BEGIN USB_LP_CAN1_RX0_IRQn 1 */ 197 | 198 | /* USER CODE END USB_LP_CAN1_RX0_IRQn 1 */ 199 | } 200 | 201 | void USART1_IRQHandler(void) 202 | { 203 | extern void Hal_uart_isr(void); 204 | Hal_uart_isr(); 205 | } 206 | -------------------------------------------------------------------------------- /app/blackpill/MSC/usbd_msc_scsi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usbd_msc_scsi.h 4 | * @author MCD Application Team 5 | * @version V2.4.2 6 | * @date 11-December-2015 7 | * @brief Header for the usbd_msc_scsi.c file 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT 2015 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 __USBD_MSC_SCSI_H 30 | #define __USBD_MSC_SCSI_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* Includes ------------------------------------------------------------------*/ 37 | #include "usbd_def.h" 38 | 39 | /** @addtogroup STM32_USB_DEVICE_LIBRARY 40 | * @{ 41 | */ 42 | 43 | /** @defgroup USBD_SCSI 44 | * @brief header file for the storage disk file 45 | * @{ 46 | */ 47 | 48 | /** @defgroup USBD_SCSI_Exported_Defines 49 | * @{ 50 | */ 51 | 52 | #define SENSE_LIST_DEEPTH 4 53 | 54 | /* SCSI Commands */ 55 | #define SCSI_FORMAT_UNIT 0x04 56 | #define SCSI_INQUIRY 0x12 57 | #define SCSI_MODE_SELECT6 0x15 58 | #define SCSI_MODE_SELECT10 0x55 59 | #define SCSI_MODE_SENSE6 0x1A 60 | #define SCSI_MODE_SENSE10 0x5A 61 | #define SCSI_ALLOW_MEDIUM_REMOVAL 0x1E 62 | #define SCSI_READ6 0x08 63 | #define SCSI_READ10 0x28 64 | #define SCSI_READ12 0xA8 65 | #define SCSI_READ16 0x88 66 | 67 | #define SCSI_READ_CAPACITY10 0x25 68 | #define SCSI_READ_CAPACITY16 0x9E 69 | 70 | #define SCSI_REQUEST_SENSE 0x03 71 | #define SCSI_START_STOP_UNIT 0x1B 72 | #define SCSI_TEST_UNIT_READY 0x00 73 | #define SCSI_WRITE6 0x0A 74 | #define SCSI_WRITE10 0x2A 75 | #define SCSI_WRITE12 0xAA 76 | #define SCSI_WRITE16 0x8A 77 | 78 | #define SCSI_VERIFY10 0x2F 79 | #define SCSI_VERIFY12 0xAF 80 | #define SCSI_VERIFY16 0x8F 81 | 82 | #define SCSI_SEND_DIAGNOSTIC 0x1D 83 | #define SCSI_READ_FORMAT_CAPACITIES 0x23 84 | 85 | #define NO_SENSE 0 86 | #define RECOVERED_ERROR 1 87 | #define NOT_READY 2 88 | #define MEDIUM_ERROR 3 89 | #define HARDWARE_ERROR 4 90 | #define ILLEGAL_REQUEST 5 91 | #define UNIT_ATTENTION 6 92 | #define DATA_PROTECT 7 93 | #define BLANK_CHECK 8 94 | #define VENDOR_SPECIFIC 9 95 | #define COPY_ABORTED 10 96 | #define ABORTED_COMMAND 11 97 | #define VOLUME_OVERFLOW 13 98 | #define MISCOMPARE 14 99 | 100 | 101 | #define INVALID_CDB 0x20 102 | #define INVALID_FIELED_IN_COMMAND 0x24 103 | #define PARAMETER_LIST_LENGTH_ERROR 0x1A 104 | #define INVALID_FIELD_IN_PARAMETER_LIST 0x26 105 | #define ADDRESS_OUT_OF_RANGE 0x21 106 | #define MEDIUM_NOT_PRESENT 0x3A 107 | #define MEDIUM_HAVE_CHANGED 0x28 108 | #define WRITE_PROTECTED 0x27 109 | #define UNRECOVERED_READ_ERROR 0x11 110 | #define WRITE_FAULT 0x03 111 | 112 | #define READ_FORMAT_CAPACITY_DATA_LEN 0x0C 113 | #define READ_CAPACITY10_DATA_LEN 0x08 114 | #define MODE_SENSE10_DATA_LEN 0x08 115 | #define MODE_SENSE6_DATA_LEN 0x04 116 | #define REQUEST_SENSE_DATA_LEN 0x12 117 | #define STANDARD_INQUIRY_DATA_LEN 0x24 118 | #define BLKVFY 0x04 119 | 120 | extern uint8_t Page00_Inquiry_Data[]; 121 | extern uint8_t Standard_Inquiry_Data[]; 122 | extern uint8_t Standard_Inquiry_Data2[]; 123 | extern uint8_t Mode_Sense6_data[]; 124 | extern uint8_t Mode_Sense10_data[]; 125 | extern uint8_t Scsi_Sense_Data[]; 126 | extern uint8_t ReadCapacity10_Data[]; 127 | extern uint8_t ReadFormatCapacity_Data []; 128 | /** 129 | * @} 130 | */ 131 | 132 | 133 | /** @defgroup USBD_SCSI_Exported_TypesDefinitions 134 | * @{ 135 | */ 136 | 137 | typedef struct _SENSE_ITEM { 138 | char Skey; 139 | union { 140 | struct _ASCs { 141 | char ASC; 142 | char ASCQ; 143 | }b; 144 | unsigned int ASC; 145 | char *pData; 146 | } w; 147 | } USBD_SCSI_SenseTypeDef; 148 | /** 149 | * @} 150 | */ 151 | 152 | /** @defgroup USBD_SCSI_Exported_Macros 153 | * @{ 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /** @defgroup USBD_SCSI_Exported_Variables 161 | * @{ 162 | */ 163 | 164 | /** 165 | * @} 166 | */ 167 | /** @defgroup USBD_SCSI_Exported_FunctionsPrototype 168 | * @{ 169 | */ 170 | int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, 171 | uint8_t lun, 172 | uint8_t *cmd); 173 | 174 | void SCSI_SenseCode(USBD_HandleTypeDef *pdev, 175 | uint8_t lun, 176 | uint8_t sKey, 177 | uint8_t ASC); 178 | 179 | /** 180 | * @} 181 | */ 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | 187 | #endif /* __USBD_MSC_SCSI_H */ 188 | /** 189 | * @} 190 | */ 191 | 192 | /** 193 | * @} 194 | */ 195 | 196 | /** 197 | * @} 198 | */ 199 | 200 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 201 | 202 | -------------------------------------------------------------------------------- /hal/blackpill/drivers/stm32f1xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * File Name : stm32f1xx_hal_msp.c 4 | * Description : This file provides code for the MSP Initialization 5 | * and de-Initialization codes. 6 | ****************************************************************************** 7 | * This notice applies to any and all portions of this file 8 | * that are not between comment pairs USER CODE BEGIN and 9 | * USER CODE END. Other portions of this file, whether 10 | * inserted by the user or by software development tools 11 | * are owned by their respective copyright owners. 12 | * 13 | * Copyright (c) 2017 STMicroelectronics International N.V. 14 | * All rights reserved. 15 | * 16 | * Redistribution and use in source and binary forms, with or without 17 | * modification, are permitted, provided that the following conditions are met: 18 | * 19 | * 1. Redistribution of source code must retain the above copyright notice, 20 | * this list of conditions and the following disclaimer. 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, 22 | * this list of conditions and the following disclaimer in the documentation 23 | * and/or other materials provided with the distribution. 24 | * 3. Neither the name of STMicroelectronics nor the names of other 25 | * contributors to this software may be used to endorse or promote products 26 | * derived from this software without specific written permission. 27 | * 4. This software, including modifications and/or derivative works of this 28 | * software, must execute solely and exclusively on microcontroller or 29 | * microprocessor devices manufactured by or for STMicroelectronics. 30 | * 5. Redistribution and use of this software other than as permitted under 31 | * this license is void and will automatically terminate your rights under 32 | * this license. 33 | * 34 | * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 35 | * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 37 | * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY 38 | * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 39 | * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 40 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 42 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 43 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 44 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 45 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | ****************************************************************************** 48 | */ 49 | /* Includes ------------------------------------------------------------------*/ 50 | #include "stm32f1xx_hal.h" 51 | 52 | extern void _Error_Handler(char *, int); 53 | /* USER CODE BEGIN 0 */ 54 | 55 | /* USER CODE END 0 */ 56 | /** 57 | * Initializes the Global MSP. 58 | */ 59 | void HAL_MspInit(void) 60 | { 61 | /* USER CODE BEGIN MspInit 0 */ 62 | 63 | /* USER CODE END MspInit 0 */ 64 | 65 | __HAL_RCC_AFIO_CLK_ENABLE(); 66 | 67 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 68 | 69 | /* System interrupt init*/ 70 | /* MemoryManagement_IRQn interrupt configuration */ 71 | HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0); 72 | /* BusFault_IRQn interrupt configuration */ 73 | HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0); 74 | /* UsageFault_IRQn interrupt configuration */ 75 | HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0); 76 | /* SVCall_IRQn interrupt configuration */ 77 | HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0); 78 | /* DebugMonitor_IRQn interrupt configuration */ 79 | HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0); 80 | /* PendSV_IRQn interrupt configuration */ 81 | HAL_NVIC_SetPriority(PendSV_IRQn, 0, 0); 82 | /* SysTick_IRQn interrupt configuration */ 83 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); 84 | 85 | /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled 86 | */ 87 | __HAL_AFIO_REMAP_SWJ_NOJTAG(); 88 | 89 | /* USER CODE BEGIN MspInit 1 */ 90 | 91 | /* USER CODE END MspInit 1 */ 92 | } 93 | 94 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) 95 | { 96 | 97 | if(htim_base->Instance==TIM1) 98 | { 99 | /* USER CODE BEGIN TIM1_MspInit 0 */ 100 | 101 | /* USER CODE END TIM1_MspInit 0 */ 102 | /* Peripheral clock enable */ 103 | __HAL_RCC_TIM1_CLK_ENABLE(); 104 | /* USER CODE BEGIN TIM1_MspInit 1 */ 105 | 106 | /* USER CODE END TIM1_MspInit 1 */ 107 | } 108 | 109 | } 110 | 111 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) 112 | { 113 | 114 | if(htim_base->Instance==TIM1) 115 | { 116 | /* USER CODE BEGIN TIM1_MspDeInit 0 */ 117 | 118 | /* USER CODE END TIM1_MspDeInit 0 */ 119 | /* Peripheral clock disable */ 120 | __HAL_RCC_TIM1_CLK_DISABLE(); 121 | /* USER CODE BEGIN TIM1_MspDeInit 1 */ 122 | 123 | /* USER CODE END TIM1_MspDeInit 1 */ 124 | } 125 | 126 | } 127 | 128 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 129 | { 130 | 131 | GPIO_InitTypeDef GPIO_InitStruct; 132 | if(huart->Instance==USART1) 133 | { 134 | /* USER CODE BEGIN USART1_MspInit 0 */ 135 | 136 | /* USER CODE END USART1_MspInit 0 */ 137 | /* Peripheral clock enable */ 138 | __HAL_RCC_USART1_CLK_ENABLE(); 139 | 140 | /**USART1 GPIO Configuration 141 | PA9 ------> USART1_TX 142 | PA10 ------> USART1_RX 143 | */ 144 | GPIO_InitStruct.Pin = GPIO_PIN_9; 145 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 146 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 147 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 148 | 149 | GPIO_InitStruct.Pin = GPIO_PIN_10; 150 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 151 | GPIO_InitStruct.Pull = GPIO_NOPULL; 152 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 153 | 154 | /* USER CODE BEGIN USART1_MspInit 1 */ 155 | 156 | /* USER CODE END USART1_MspInit 1 */ 157 | } 158 | 159 | } 160 | 161 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 162 | { 163 | 164 | if(huart->Instance==USART1) 165 | { 166 | /* USER CODE BEGIN USART1_MspDeInit 0 */ 167 | 168 | /* USER CODE END USART1_MspDeInit 0 */ 169 | /* Peripheral clock disable */ 170 | __HAL_RCC_USART1_CLK_DISABLE(); 171 | 172 | /**USART1 GPIO Configuration 173 | PA9 ------> USART1_TX 174 | PA10 ------> USART1_RX 175 | */ 176 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 177 | 178 | /* USER CODE BEGIN USART1_MspDeInit 1 */ 179 | 180 | /* USER CODE END USART1_MspDeInit 1 */ 181 | } 182 | 183 | } 184 | 185 | /* USER CODE BEGIN 1 */ 186 | 187 | /* USER CODE END 1 */ 188 | 189 | /** 190 | * @} 191 | */ 192 | 193 | /** 194 | * @} 195 | */ 196 | 197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 198 | -------------------------------------------------------------------------------- /app/blackpill/Layout/cambrian/Layout.c: -------------------------------------------------------------------------------- 1 | #include "KeyHw.h" 2 | #include "keymap.h" 3 | #include "Layout.h" 4 | 5 | #include "stm32f1xx_hal.h" 6 | 7 | /* Cambrian Keylayout 8 | * COL (input) 9 | * +--------+------------------------------------------------ -----------------------------------------------------+------+ 10 | * | Col# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 11 | * +--------+------+-------+-----+-----+-----+-------+------+ +-----+-----+-----+-----+------+-------+-------+-----+------+ 12 | * |R# | | PA5 | PA6 | PA7 | PB0 | PB1 | PB10 | PB11 | | PB7 | PB6 | PB5 | PB4 | PB3 | PB15 | PB14 | PB13| PB12 | 13 | * +---+----+------+-------+-----+-----+-----+-------+------+ +-----+-----+-----+-----+------+-------+-------+-----+------+ 14 | * | 0 |PA0 | | | | 15 | * | 1 |PA1 | | | | 16 | * ROW | 2 |PA2 | Left Part (7cols) | | Right Part (9cols) | 17 | *(out) | 3 |PA3 | | | | 18 | * | 4 |PA4 | | | | 19 | * +-- +----------------------------------------------------+ +-----------------------------------------------------------+ 20 | * 21 | */ 22 | 23 | /* Extra Pin usage 24 | * PA9, PA10 - UART1 - Debug CLI 25 | * PA11, PA12 - USB 26 | */ 27 | 28 | Keypin_t gRowPin[KEYMAP_ROW_NUM] = { 29 | {(uint32_t)GPIOA, GPIO_PIN_4}, 30 | {(uint32_t)GPIOA, GPIO_PIN_3}, 31 | {(uint32_t)GPIOA, GPIO_PIN_2}, 32 | {(uint32_t)GPIOA, GPIO_PIN_1}, 33 | {(uint32_t)GPIOA, GPIO_PIN_0} 34 | }; 35 | 36 | Keypin_t gColPin[KEYMAP_COL_NUM] = { 37 | // Left Part 38 | {(uint32_t)GPIOA, GPIO_PIN_5}, 39 | {(uint32_t)GPIOA, GPIO_PIN_6}, 40 | {(uint32_t)GPIOA, GPIO_PIN_7}, 41 | {(uint32_t)GPIOB, GPIO_PIN_0}, 42 | {(uint32_t)GPIOB, GPIO_PIN_1}, 43 | {(uint32_t)GPIOB, GPIO_PIN_10}, 44 | {(uint32_t)GPIOB, GPIO_PIN_11}, 45 | // Right Part 46 | {(uint32_t)GPIOB, GPIO_PIN_7}, 47 | {(uint32_t)GPIOB, GPIO_PIN_6}, 48 | {(uint32_t)GPIOB, GPIO_PIN_5}, 49 | {(uint32_t)GPIOB, GPIO_PIN_4}, 50 | {(uint32_t)GPIOB, GPIO_PIN_3}, 51 | {(uint32_t)GPIOB, GPIO_PIN_15}, 52 | {(uint32_t)GPIOB, GPIO_PIN_14}, 53 | {(uint32_t)GPIOB, GPIO_PIN_13} 54 | }; 55 | 56 | 57 | /* Default Keymap 58 | * **** Layer 0 **** 59 | * COL (input) 60 | * +----+---------------------------------------+ +----------------------------------------------- 61 | * |Col#| 0 | 1 | 2 | 3 | 4 | 5 | 6 | | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 62 | * +----+------+-----+-----+-----+----+----+----+ +----+-----+-----+-----+----+----+-------+-----+ 63 | * | 0 | ESC | 1 | 2 | 3 | 4 | 5 | 6 | | 7 | 8 | 9 | 0 | - | + | Back | Del | 64 | * | 1 | Tab | Q | W | E | R | T | | | Y | U | I | O | P | [ | ] | \ | 65 | * ROW | 2 | Fn | A | S | D | F | G | | | H | J | K | L | ; | " | Enter | End | 66 | *(out) | 3 |Shift | Z | X | C | V | B | | | B | N | M | < | > | ? | Shift | ↑ | 67 | * | 4 | Ctrl | Win | Alt | Spc | | | | | Spc| Fn | Alt |Ctrl | ← | ↓ | → |Home | 68 | * +----+---------------------------------------+ +----------------------------------------------+ 69 | * 70 | * **** Layer 1 **** 71 | * COL (input) 72 | * +----+---------------------------------------+ +----------------------------------------------- 73 | * |Col#| 0 | 1 | 2 | 3 | 4 | 5 | 6 | | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 74 | * +----+------+-----+-----+-----+----+----+----+ +----+-----+-----+-----+----+----+-------+-----+ 75 | * | 0 | ` | F1 | F2 | F3 | F4 | F5 | F6 | | F7 | F8 | F9 | F10 | F11| F12| | | 76 | * | 1 | | | | | | | | | | | | | | | | | 77 | * ROW | 2 | | | | | | | | | | | | | | | | PgD | 78 | *(out) | 3 | | | | | | | | | | | | | | | | | 79 | * | 4 | | | | | | | | | | | | | | | |PgUp | 80 | * +----+---------------------------------------+ +----------------------------------------------+ 81 | * 82 | */ 83 | uint8_t gKeymap_buffer_layer0[KEYMAP_ROW_NUM][KEYMAP_COL_NUM] = 84 | { /* Col#0 Col#1 Col#2 Col#3 Col#4 Col#5 Col#6 || Col#7 Col#8 Col#9 Col#10 Col#11 Col#12 Col#13 Col#14 */ 85 | /* Row#0 */ {kEsc, k1, k2, k3, k4, k5, k6, k7, k8, k9, k0, kMinus, kEqual, kBackspace, kDelete}, 86 | /* Row#1 */ {kTab, kQ, kW, kE, kR, kT, kNone, kY, kU, kI, kO, kP, kLeftbrace, kRightbrace, kBackslash}, 87 | /* Row#2 */ {kFunction, kA, kS, kD, kF, kG, kNone, kH, kJ, kK, kL, kSemicolon, kApostrophe, kEnter, kEnd}, 88 | /* Row#3 */ {kLeftshift,kZ, kX, kC, kV, kB, kNone, kB, kN, kM, kComma, kDot, kSlash, kRightshift, kUp}, 89 | /* Row#4 */ {kLeftctrl, kLeftmeta, kLeftalt, kSpace, kNone, kNone, kNone, kSpace, kFunction, kRightalt, kRightctrl, kLeft, kDown, kRight, kHome} 90 | }; 91 | 92 | uint8_t gKeymap_buffer_layer1[KEYMAP_ROW_NUM][KEYMAP_COL_NUM] = 93 | { /* Col#0 Col#1 Col#2 Col#3 Col#4 Col#5 Col#6 Col#7 Col#8 Col#9 Col#10 Col#11 Col#12 Col#13 Col14 */ 94 | /* Row#0 */ {kGrave, kF1, kF2, kF3, kF4, kF5, kF6, kF7, kF8, kF9, kF10, kF11, kF12, kNone, kNone}, 95 | /* Row#1 */ {0}, 96 | /* Row#2 */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, kPagedown}, 97 | /* Row#3 */ {0}, 98 | /* Row#4 */ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, kPageup} 99 | }; 100 | 101 | void ChangeReportByLayout(uint8_t *report) 102 | { 103 | /* Modifier bitmap 104 | 105 | kModLctrl = 0x01, 106 | kModLshift = 0x02, 107 | kModLalt = 0x04, 108 | kModLmeta = 0x08, 109 | kModRctrl = 0x10, 110 | kModRshift = 0x20, 111 | kModRalt = 0x40, 112 | kModRmeta = 0x80 113 | */ 114 | 115 | // Check it has left-shift or right-shift 116 | uint8_t left_right_shift_bitmap = 0x02 | 0x20; 117 | if ((report[HID_MODIKEY_IDX] & left_right_shift_bitmap) == 0) 118 | { 119 | // No shift, do nothing 120 | return; 121 | } 122 | 123 | // Check it has ESC 124 | for (uint8_t i = HID_KEY_START_IDX ; i < HID_KBD_REPORT_BYTE ; i++) 125 | { 126 | if (report[i] == kEsc) 127 | { 128 | // Change kEsc to kGrave 129 | report[i] = kGrave; 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /app/blackpill/Keycode.h: -------------------------------------------------------------------------------- 1 | #ifndef APP_KEYCODE 2 | #define APP_KEYCODE 3 | 4 | /* Modifier: First byte in HID report */ 5 | typedef enum HidMod { 6 | kModLctrl = 0x01, 7 | kModLshift = 0x02, 8 | kModLalt = 0x04, 9 | kModLmeta = 0x08, 10 | kModRctrl = 0x10, 11 | kModRshift = 0x20, 12 | kModRalt = 0x40, 13 | kModRmeta = 0x80 14 | } HidMod_t; 15 | 16 | typedef enum Scancode { 17 | kNone = 0x00, 18 | kErrOvf = 0x01, /* Keyboard Error Roll Over */ 19 | kA = 0x04, 20 | kB = 0x05, 21 | kC = 0x06, 22 | kD = 0x07, 23 | kE = 0x08, 24 | kF = 0x09, 25 | kG = 0x0a, 26 | kH = 0x0b, 27 | kI = 0x0c, 28 | kJ = 0x0d, 29 | kK = 0x0e, 30 | kL = 0x0f, 31 | kM = 0x10, 32 | kN = 0x11, 33 | kO = 0x12, 34 | kP = 0x13, 35 | kQ = 0x14, 36 | kR = 0x15, 37 | kS = 0x16, 38 | kT = 0x17, 39 | kU = 0x18, 40 | kV = 0x19, 41 | kW = 0x1a, 42 | kX = 0x1b, 43 | kY = 0x1c, 44 | kZ = 0x1d, 45 | 46 | k1 = 0x1e, 47 | k2 = 0x1f, 48 | k3 = 0x20, 49 | k4 = 0x21, 50 | k5 = 0x22, 51 | k6 = 0x23, 52 | k7 = 0x24, 53 | k8 = 0x25, 54 | k9 = 0x26, 55 | k0 = 0x27, 56 | 57 | kEnter = 0x28, 58 | kEsc = 0x29, 59 | kBackspace = 0x2a, 60 | kTab = 0x2b, 61 | kSpace = 0x2c, 62 | kMinus = 0x2d, 63 | kEqual = 0x2e, 64 | kLeftbrace = 0x2f, 65 | kRightbrace = 0x30, 66 | kBackslash = 0x31, /* \ and | */ 67 | kHashtilde = 0x32, /* Non-US # and ~ */ 68 | kSemicolon = 0x33, 69 | kApostrophe = 0x34, 70 | kGrave = 0x35, /* ` and ~ */ 71 | kComma = 0x36, /* , and < */ 72 | kDot = 0x37, /* . and > */ 73 | kSlash = 0x38, /* / and ? */ 74 | kCapslock = 0x39, 75 | 76 | kF1 = 0x3a, 77 | kF2 = 0x3b, 78 | kF3 = 0x3c, 79 | kF4 = 0x3d, 80 | kF5 = 0x3e, 81 | kF6 = 0x3f, 82 | kF7 = 0x40, 83 | kF8 = 0x41, 84 | kF9 = 0x42, 85 | kF10 = 0x43, 86 | kF11 = 0x44, 87 | kF12 = 0x45, 88 | 89 | kSysreq = 0x46, /* PrintScrn */ 90 | kScrolllock = 0x47, /* Scroll Lock */ 91 | kPause = 0x48, 92 | kInsert = 0x49, 93 | kHome = 0x4a, 94 | kPageup = 0x4b, 95 | kDelete = 0x4c, 96 | kEnd = 0x4d, 97 | kPagedown = 0x4e, 98 | kRight = 0x4f, 99 | kLeft = 0x50, 100 | kDown = 0x51, 101 | kUp = 0x52, 102 | 103 | kNumlock = 0x53, 104 | kKpslash = 0x54, // Keypad / 105 | kKpasterisk = 0x55, // Keypad * 106 | kKpminus = 0x56, // Keypad - 107 | kKpplus = 0x57, // Keypad + 108 | kKpenter = 0x58, // Keypad ENTER 109 | kKp1 = 0x59, // Keypad 1 and End 110 | kKp2 = 0x5a, // Keypad 2 and Down Arrow 111 | kKp3 = 0x5b, // Keypad 3 and PageDn 112 | kKp4 = 0x5c, // Keypad 4 and Left Arrow 113 | kKp5 = 0x5d, // Keypad 5 114 | kKp6 = 0x5e, // Keypad 6 and Right Arrow 115 | kKp7 = 0x5f, // Keypad 7 and Home 116 | kKp8 = 0x60, // Keypad 8 and Up Arrow 117 | kKp9 = 0x61, // Keypad 9 and Page Up 118 | kKp0 = 0x62, // Keypad 0 and Insert 119 | kKpdot = 0x63, // Keypad . and Delete 120 | 121 | k102nd = 0x64, // Keyboard Non-US \ and | 122 | kCompose = 0x65, // Keyboard Application 123 | kPower = 0x66, // Keyboard Power 124 | kKpequal = 0x67, // Keypad = 125 | 126 | kF13 = 0x68, // Keyboard F13 127 | kF14 = 0x69, // Keyboard F14 128 | kF15 = 0x6a, // Keyboard F15 129 | kF16 = 0x6b, // Keyboard F16 130 | kF17 = 0x6c, // Keyboard F17 131 | kF18 = 0x6d, // Keyboard F18 132 | kF19 = 0x6e, // Keyboard F19 133 | kF20 = 0x6f, // Keyboard F20 134 | kF21 = 0x70, // Keyboard F21 135 | kF22 = 0x71, // Keyboard F22 136 | kF23 = 0x72, // Keyboard F23 137 | kF24 = 0x73, // Keyboard F24 138 | 139 | kOpen = 0x74, // Keyboard Execute 140 | kHelp = 0x75, // Keyboard Help 141 | kProps = 0x76, // Keyboard Menu 142 | kFront = 0x77, // Keyboard Select 143 | kStop = 0x78, // Keyboard Stop 144 | kAgain = 0x79, // Keyboard Again 145 | kUndo = 0x7a, // Keyboard Undo 146 | kCut = 0x7b, // Keyboard Cut 147 | kCopy = 0x7c, // Keyboard Copy 148 | kPaste = 0x7d, // Keyboard Paste 149 | kFind = 0x7e, // Keyboard Find 150 | kMute = 0x7f, // Keyboard Mute 151 | kVup = 0x80, // Keyboard Volume Up 152 | kVdown = 0x81, // Keyboard Volume Down 153 | // 0x82 Keyboard Locking Caps Lock 154 | // 0x83 Keyboard Locking Num Lock 155 | // 0x84 Keyboard Locking Scroll Lock 156 | kKpcomma = 0x85, // Keypad Comma 157 | // 0x86 Keypad Equal Sign 158 | Kro = 0x87, // Keyboard International1 159 | kKatakanahiragana = 0x88, // Keyboard International2 160 | kYen = 0x89, // Keyboard International3 161 | kHenkan = 0x8a, // Keyboard International4 162 | kMuhenkan = 0x8b, // Keyboard International5 163 | kKpjpcomma = 0x8c, // Keyboard International6 164 | // 0x8d Keyboard International7 165 | // 0x8e Keyboard International8 166 | // 0x8f Keyboard International9 167 | kHangeul = 0x90, // Keyboard LANG1 168 | Khanja = 0x91, // Keyboard LANG2 169 | kKatakana = 0x92, // Keyboard LANG3 170 | kHiragana = 0x93, // Keyboard LANG4 171 | kZenkakuhankaku = 0x94, // Keyboard LANG5 172 | // 0x95 Keyboard LANG6 173 | // 0x96 Keyboard LANG7 174 | // 0x97 Keyboard LANG8 175 | // 0x98 Keyboard LANG9 176 | // 0x99 Keyboard Alternate Erase 177 | // 0x9a Keyboard SysReq/Attention 178 | // 0x9b Keyboard Cancel 179 | // 0x9c Keyboard Clear 180 | // 0x9d Keyboard Prior 181 | // 0x9e Keyboard Return 182 | // 0x9f Keyboard Separator 183 | // 0xa0 Keyboard Out 184 | // 0xa1 Keyboard Oper 185 | // 0xa2 Keyboard Clear/Again 186 | // 0xa3 Keyboard CrSel/Props 187 | // 0xa4 Keyboard ExSel 188 | 189 | // 0xb0 Keypad 00 190 | // 0xb1 Keypad 000 191 | // 0xb2 Thousands Separator 192 | // 0xb3 Decimal Separator 193 | // 0xb4 Currency Unit 194 | // 0xb5 Currency Sub-unit 195 | kKpleftparen = 0xb6, // Keypad ( 196 | kKprightparen = 0xb7, // Keypad ) 197 | // 0xb8 Keypad { 198 | // 0xb9 Keypad } 199 | // 0xba Keypad Tab 200 | // 0xbb Keypad Backspace 201 | // 0xbc Keypad A 202 | // 0xbd Keypad B 203 | // 0xbe Keypad C 204 | // 0xbf Keypad D 205 | // 0xc0 Keypad E 206 | // 0xc1 Keypad F 207 | // 0xc2 Keypad XOR 208 | // 0xc3 Keypad ^ 209 | // 0xc4 Keypad % 210 | // 0xc5 Keypad < 211 | // 0xc6 Keypad > 212 | // 0xc7 Keypad & 213 | // 0xc8 Keypad && 214 | // 0xc9 Keypad | 215 | // 0xca Keypad || 216 | // 0xcb Keypad : 217 | // 0xcc Keypad # 218 | // 0xcd Keypad Space 219 | // 0xce Keypad @ 220 | // 0xcf Keypad ! 221 | // 0xd0 Keypad Memory Store 222 | // 0xd1 Keypad Memory Recall 223 | // 0xd2 Keypad Memory Clear 224 | // 0xd3 Keypad Memory Add 225 | // 0xd4 Keypad Memory Subtract 226 | // 0xd5 Keypad Memory Multiply 227 | // 0xd6 Keypad Memory Divide 228 | // 0xd7 Keypad +/- 229 | // 0xd8 Keypad Clear 230 | // 0xd9 Keypad Clear Entry 231 | // 0xda Keypad Binary 232 | // 0xdb Keypad Octal 233 | // 0xdc Keypad Decimal 234 | // 0xdd Keypad Hexadecimal 235 | 236 | kLeftctrl = 0xe0, // Keyboard Left Control 237 | kLeftshift = 0xe1, // Keyboard Left Shift 238 | kLeftalt = 0xe2, // Keyboard Left Alt 239 | kLeftmeta = 0xe3, // Keyboard Left GUI 240 | kRightctrl = 0xe4, // Keyboard Right Control 241 | kRightshift = 0xe5, // Keyboard Right Shift 242 | kRightalt = 0xe6, // Keyboard Right Alt 243 | kRightmeta = 0xe7, // Keyboard Right GUI 244 | 245 | kMplaypause = 0xe8, 246 | kMstopcd = 0xe9, 247 | kMprevioussong = 0xea, 248 | kMnextsong = 0xeb, 249 | kMejectcd = 0xec, 250 | kMvolumeup = 0xed, 251 | kMvolumedown = 0xee, 252 | kMmute = 0xef, 253 | kMwww = 0xf0, 254 | kMback = 0xf1, 255 | kMforward = 0xf2, 256 | kMstop = 0xf3, 257 | kMfind = 0xf4, 258 | kMscrollup = 0xf5, 259 | kMscrolldown = 0xf6, 260 | kMedit = 0xf7, 261 | kMsleep = 0xf8, 262 | kMcoffee = 0xf9, 263 | kMrefresh = 0xfa, 264 | kMcalc = 0xfb, 265 | kFunction = 0xff /* Gosu defined scan code for Fn key */ 266 | } Scancode_t; 267 | 268 | #endif 269 | -------------------------------------------------------------------------------- /.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 48 | 49 | 50 | 51 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | --------------------------------------------------------------------------------