Skip to content

Commit

Permalink
add new feature
Browse files Browse the repository at this point in the history
bootloader jumper
keycode
  • Loading branch information
mo10 committed Aug 12, 2019
1 parent a140614 commit 7ebc26c
Show file tree
Hide file tree
Showing 10 changed files with 326 additions and 63 deletions.
13 changes: 13 additions & 0 deletions Firmware/Pigeon/Inc/bootloader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __BOOTLOADER_H__
#define __BOOTLOADER_H__

#include "main.h"

#define BOOTLOADER_MAGIC_ADDR ((uint32_t*) ((uint32_t) 0x20001000)) //4k into SRAM (out of 6k)
#define BOOTLOADER_MAGIC_TOKEN 0xDEADBEEF // :D//Value taken from CD00167594.pdf page 35, system memory start.
#define BOOTLOADER_START_ADDR 0x1fffc400 //for ST32F042

void BOOTLOADER_Init();
void BOOTLOADER_Jump();

#endif //__BOOTLOADER_H__
13 changes: 12 additions & 1 deletion Firmware/Pigeon/Inc/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
#define __EEPROM_H__

#include "st7735_hal.h"

#include "keycode.h"
typedef struct EEPROM{
uint8_t ProfileIdx;
uint8_t KeyDef;
KEY_REPORT_TypeDef KeyReports[];
uint8_t Brightness;
uint16_t ColorTab[4];
uint16_t RLELen;
uint16_t RLEData[];
} EEPROM_TypeDef;

typedef enum Key
{
EEPROM_KEY_NONE,
EEPROM_KEY_KBD,
EEPROM_KEY_EVENT,
EEPROM_KEY_BOTH,
}EEPROM_KeyTypeDef;

EEPROM_TypeDef * EEPROM_GetData();

#endif //__EEPROM_H__
51 changes: 51 additions & 0 deletions Firmware/Pigeon/Inc/keycode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef __KEYCODE_H__
#define __KEYCODE_H__

#include <stdint.h>

#define SHIFT 0x80

#define KEY_LEFT_CTRL 0x80
#define KEY_LEFT_SHIFT 0x81
#define KEY_LEFT_ALT 0x82
#define KEY_LEFT_GUI 0x83
#define KEY_RIGHT_CTRL 0x84
#define KEY_RIGHT_SHIFT 0x85
#define KEY_RIGHT_ALT 0x86
#define KEY_RIGHT_GUI 0x87

#define KEY_UP_ARROW 0xDA
#define KEY_DOWN_ARROW 0xD9
#define KEY_LEFT_ARROW 0xD8
#define KEY_RIGHT_ARROW 0xD7
#define KEY_BACKSPACE 0xB2
#define KEY_TAB 0xB3
#define KEY_RETURN 0xB0
#define KEY_ESC 0xB1
#define KEY_INSERT 0xD1
#define KEY_DELETE 0xD4
#define KEY_PAGE_UP 0xD3
#define KEY_PAGE_DOWN 0xD6
#define KEY_HOME 0xD2
#define KEY_END 0xD5
#define KEY_CAPS_LOCK 0xC1
#define KEY_F1 0xC2
#define KEY_F2 0xC3
#define KEY_F3 0xC4
#define KEY_F4 0xC5
#define KEY_F5 0xC6
#define KEY_F6 0xC7
#define KEY_F7 0xC8
#define KEY_F8 0xC9
#define KEY_F9 0xCA
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD

typedef KEY_REPORT{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
}KEY_REPORT_TypeDef;

#endif
1 change: 1 addition & 0 deletions Firmware/Pigeon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BUILD_DIR = build
# C sources
C_SOURCES = \
Src/eeprom.c \
Src/bootloader.c \
Src/st7735_hal.c \
Src/fonts.c \
Src/main.c \
Expand Down
33 changes: 33 additions & 0 deletions Firmware/Pigeon/Src/bootloader.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "bootloader.h"

void BOOTLOADER_Jump(){
//https://community.st.com/s/question/0D50X00009Xkg1VSAR/jump-to-usb-dfu-bootloader-in-startup-code-on-stm32f042
//call this at any time to initiate a reboot into bootloader
*BOOTLOADER_MAGIC_ADDR = BOOTLOADER_MAGIC_TOKEN;
NVIC_SystemReset();
}
void BOOTLOADER_Init(){
uint32_t jumpaddr;
if (*BOOTLOADER_MAGIC_ADDR == BOOTLOADER_MAGIC_TOKEN){
// 要求转跳Bootloader
*BOOTLOADER_MAGIC_ADDR=0;
// 初始化Boot0引脚
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); // 拉高Boot0

void (*bootloader)(void) = 0; //Zero the function pointer.
jumpaddr = *(__IO uint32_t*)(BOOTLOADER_START_ADDR + 4);
bootloader = (void (*)(void)) jumpaddr; //Set the function pointerto bootaddr +4
__set_MSP(*(__IO uint32_t*) BOOTLOADER_START_ADDR); //load the stackpointer - bye bye program
bootloader(); //Go to DFU mode
//this should never be hit, trap for debugging
while(1){}
}
}
130 changes: 73 additions & 57 deletions Firmware/Pigeon/Src/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
EEPROM_TypeDef _eep __attribute__ ((section(".eeprom"),used))= {
/* Screen configuration profile index */
.ProfileIdx = 0,
/* Key function setting */
.KeyDef = EEPROM_KEY_BOTH,
.KeyStrLen = 12,
.KeyStr = 'H','e','l','l','o',' ','w','o','r','l','d','!',
/* Screen brightness */
.Brightness = 10,
/* Default color table */
.ColorTab = {
ST7735_COLOR565(255, 255, 255),ST7735_COLOR565(0, 162, 232),
ST7735_COLOR565(181, 230, 29),ST7735_COLOR565(0, 0, 0)
ST7735_COLOR565(255, 255, 255),
ST7735_COLOR565(0, 162, 232),
ST7735_COLOR565(181, 230, 29),
},
/* RLE data length, calculated based on uint16_t */
.RLELen = 523,
.RLELen = 615,
/* RLE data(splash screen image)*/
.RLEData = {
0x03dd, 0x4004, 0x009b, 0x4006, 0x009a, 0x4006, 0x0099, 0x4007,
Expand All @@ -27,60 +32,71 @@ EEPROM_TypeDef _eep __attribute__ ((section(".eeprom"),used))= {
0x0067, 0x4010, 0x0004, 0x400c, 0x0004, 0x4014, 0x0068, 0x4011,
0x0005, 0x400a, 0x0004, 0x4009, 0x0002, 0x4009, 0x0068, 0x4012,
0x0006, 0x4008, 0x0004, 0x4009, 0x0002, 0x4009, 0x0068, 0x4014,
0x0006, 0x4006, 0x0004, 0x4014, 0x0017, 0x8003, 0x004e, 0x4016,
0x0006, 0x4004, 0x0004, 0x4014, 0x0007, 0x8009, 0x0007, 0x8003,
0x004e, 0x4017, 0x000d, 0x4014, 0x0007, 0x800b, 0x0005, 0x8003,
0x004e, 0x401a, 0x000a, 0x4014, 0x0007, 0x8003, 0x0005, 0x8004,
0x0055, 0x401c, 0x0008, 0x4014, 0x0007, 0x8003, 0x0006, 0x8004,
0x0054, 0x4021, 0x0003, 0x4014, 0x0007, 0x8003, 0x0007, 0x8003,
0x0054, 0x4038, 0x0007, 0x8003, 0x0007, 0x8003, 0x0003, 0x8003,
0x0007, 0x8005, 0x0002, 0x8003, 0x0007, 0x8006, 0x000a, 0x8006,
0x0007, 0x8003, 0x0002, 0x8005, 0x000f, 0x4038, 0x0007, 0x8003,
0x0007, 0x8003, 0x0003, 0x8003, 0x0005, 0x8008, 0x0001, 0x8003,
0x0006, 0x8008, 0x0007, 0x800a, 0x0005, 0x8003, 0x0001, 0x8008,
0x000e, 0x4037, 0x0007, 0x8003, 0x0007, 0x8003, 0x0003, 0x8003,
0x0005, 0x8003, 0x0004, 0x8005, 0x0005, 0x8003, 0x0004, 0x8003,
0x0005, 0x8003, 0x0005, 0x8004, 0x0004, 0x8005, 0x0004, 0x8003,
0x000e, 0x4037, 0x0007, 0x8003, 0x0006, 0x8003, 0x0004, 0x8003,
0x0004, 0x8003, 0x0006, 0x8004, 0x0004, 0x8003, 0x0005, 0x8003,
0x0004, 0x8003, 0x0007, 0x8003, 0x0004, 0x8004, 0x0005, 0x8004,
0x000d, 0x4037, 0x0007, 0x8003, 0x0005, 0x8004, 0x0004, 0x8003,
0x0004, 0x8003, 0x0007, 0x8003, 0x0004, 0x8002, 0x0007, 0x8003,
0x0003, 0x8003, 0x0007, 0x8004, 0x0003, 0x8003, 0x0007, 0x8003,
0x000e, 0x4036, 0x0007, 0x800b, 0x0005, 0x8003, 0x0003, 0x8003,
0x0008, 0x8003, 0x0003, 0x8003, 0x0007, 0x8003, 0x0002, 0x8003,
0x0009, 0x8003, 0x0003, 0x8003, 0x0007, 0x8003, 0x000e, 0x4036,
0x0007, 0x8009, 0x0007, 0x8003, 0x0003, 0x8003, 0x0008, 0x8003,
0x0003, 0x800d, 0x0002, 0x8003, 0x0009, 0x8003, 0x0003, 0x8003,
0x0007, 0x8003, 0x000e, 0x4036, 0x0007, 0x8003, 0x000d, 0x8003,
0x0003, 0x8003, 0x0008, 0x8003, 0x0003, 0x800d, 0x0002, 0x8003,
0x0009, 0x8003, 0x0003, 0x8003, 0x0007, 0x8003, 0x000f, 0x4035,
0x0007, 0x8003, 0x000d, 0x8003, 0x0003, 0x8003, 0x0008, 0x8003,
0x0003, 0x8003, 0x000c, 0x8003, 0x0009, 0x8003, 0x0003, 0x8003,
0x0007, 0x8003, 0x000f, 0x4035, 0x0007, 0x8003, 0x000d, 0x8003,
0x0003, 0x8003, 0x0008, 0x8003, 0x0003, 0x8003, 0x000c, 0x8003,
0x0009, 0x8003, 0x0003, 0x8003, 0x0007, 0x8003, 0x0010, 0x4034,
0x0007, 0x8003, 0x000d, 0x8003, 0x0003, 0x8003, 0x0008, 0x8003,
0x0003, 0x8003, 0x000c, 0x8004, 0x0008, 0x8002, 0x0004, 0x8003,
0x0007, 0x8003, 0x0011, 0x4033, 0x0007, 0x8003, 0x000d, 0x8003,
0x0004, 0x8003, 0x0006, 0x8004, 0x0004, 0x8003, 0x0007, 0x8001,
0x0004, 0x8003, 0x0007, 0x8003, 0x0004, 0x8003, 0x0007, 0x8003,
0x0011, 0x4033, 0x0007, 0x8003, 0x000d, 0x8003, 0x0004, 0x8004,
0x0004, 0x8005, 0x0004, 0x8004, 0x0005, 0x8002, 0x0005, 0x8003,
0x0005, 0x8003, 0x0005, 0x8003, 0x0007, 0x8003, 0x0012, 0x4032,
0x0007, 0x8003, 0x000d, 0x8003, 0x0005, 0x8008, 0x0001, 0x8003,
0x0005, 0x8009, 0x0007, 0x8009, 0x0006, 0x8003, 0x0007, 0x8003,
0x0013, 0x4031, 0x0007, 0x8003, 0x000d, 0x8003, 0x0007, 0x8005,
0x0002, 0x8003, 0x0007, 0x8006, 0x0009, 0x8006, 0x0008, 0x8003,
0x0007, 0x8003, 0x0014, 0x4030, 0x0028, 0x8003, 0x0045, 0x4030,
0x0028, 0x8003, 0x0046, 0x402f, 0x0027, 0x8003, 0x0048, 0x402d,
0x0028, 0x8003, 0x004a, 0x402b, 0x001f, 0x8002, 0x0005, 0x8004,
0x004c, 0x4029, 0x0020, 0x800a, 0x004e, 0x4028, 0x0022, 0x8006,
0x004d, 0x402a, 0x0072, 0x402d, 0x006f, 0x4031, 0x006b, 0x4034,
0x0069, 0x4036, 0x006a, 0x4034, 0x006c, 0x4033, 0x006d, 0x4031,
0x006f, 0x402f, 0x0072, 0x401e, 0x0083, 0x401c, 0x0085, 0x4019,
0x0088, 0x4017, 0x008b, 0x4014, 0x008d, 0x4012, 0x0090, 0x400f,
0x0095, 0x400a, 0x06c5,
0x0006, 0x4006, 0x0004, 0x4014, 0x0068, 0x4016, 0x0006, 0x4004,
0x0004, 0x4014, 0x0068, 0x4017, 0x000d, 0x4014, 0x001d, 0x8002,
0x0019, 0x8002, 0x0019, 0x8002, 0x0013, 0x401a, 0x000a, 0x4014,
0x001d, 0x8002, 0x0019, 0x8002, 0x0019, 0x8002, 0x0013, 0x401c,
0x0008, 0x4014, 0x000e, 0x8008, 0x0007, 0x8002, 0x000a, 0x8008,
0x0007, 0x8002, 0x000a, 0x8008, 0x0007, 0x8002, 0x0013, 0x4021,
0x0003, 0x4014, 0x000e, 0x8008, 0x0007, 0x8002, 0x000a, 0x8008,
0x0007, 0x8002, 0x000a, 0x8008, 0x0007, 0x8002, 0x0013, 0x4038,
0x000e, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002,
0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x0013, 0x4038, 0x000e, 0x8002, 0x0004, 0x8002,
0x0001, 0x800f, 0x0003, 0x8002, 0x0004, 0x8002, 0x0001, 0x800f,
0x0003, 0x8002, 0x0004, 0x8002, 0x0001, 0x800f, 0x000d, 0x4037,
0x000e, 0x8002, 0x0004, 0x8002, 0x0001, 0x800f, 0x0003, 0x8002,
0x0004, 0x8002, 0x0001, 0x800f, 0x0003, 0x8002, 0x0004, 0x8002,
0x0001, 0x800f, 0x000d, 0x4037, 0x000e, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002,
0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x0014, 0x4037,
0x000e, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002,
0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x0015, 0x4036, 0x000e, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002,
0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x0015, 0x4036,
0x000e, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002,
0x0004, 0x8002, 0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x0015, 0x4036, 0x000e, 0x8002, 0x0004, 0x8002,
0x0007, 0x8002, 0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002,
0x000a, 0x8002, 0x0004, 0x8002, 0x0007, 0x8002, 0x0016, 0x4035,
0x000e, 0x8002, 0x0004, 0x8002, 0x0002, 0x800d, 0x0004, 0x8002,
0x0004, 0x8002, 0x0002, 0x800d, 0x0004, 0x8002, 0x0004, 0x8002,
0x0002, 0x800d, 0x0010, 0x4035, 0x000e, 0x8002, 0x0004, 0x8002,
0x0002, 0x800d, 0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x800d,
0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x800d, 0x0011, 0x4034,
0x000e, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0012, 0x4033, 0x000e, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002,
0x0009, 0x8002, 0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002,
0x0009, 0x8002, 0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002,
0x0009, 0x8002, 0x0012, 0x4033, 0x000e, 0x8002, 0x0004, 0x8002,
0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8002, 0x0004, 0x8002,
0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8002, 0x0004, 0x8002,
0x0002, 0x8002, 0x0009, 0x8002, 0x0013, 0x4032, 0x000e, 0x8008,
0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8008, 0x0002, 0x8002,
0x0009, 0x8002, 0x0004, 0x8008, 0x0002, 0x8002, 0x0009, 0x8002,
0x0014, 0x4031, 0x000e, 0x8008, 0x0002, 0x8002, 0x0009, 0x8002,
0x0004, 0x8008, 0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8008,
0x0002, 0x8002, 0x0009, 0x8002, 0x0015, 0x4030, 0x000e, 0x8002,
0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8002,
0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002, 0x0004, 0x8002,
0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002, 0x0015, 0x4030,
0x000e, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0004, 0x8002, 0x0004, 0x8002, 0x0002, 0x8002, 0x0009, 0x8002,
0x0016, 0x402f, 0x000e, 0x8002, 0x0008, 0x800d, 0x0004, 0x8002,
0x0008, 0x800d, 0x0004, 0x8002, 0x0008, 0x800d, 0x0017, 0x402d,
0x0019, 0x800d, 0x000e, 0x800d, 0x000e, 0x800d, 0x0019, 0x402b,
0x0019, 0x8002, 0x0009, 0x8002, 0x000e, 0x8002, 0x0009, 0x8002,
0x000e, 0x8002, 0x0009, 0x8002, 0x001a, 0x4029, 0x001a, 0x8002,
0x0009, 0x8002, 0x000e, 0x8002, 0x0009, 0x8002, 0x000e, 0x8002,
0x0009, 0x8002, 0x001b, 0x4028, 0x0075, 0x402a, 0x0072, 0x402d,
0x006f, 0x4031, 0x006b, 0x4034, 0x0069, 0x4036, 0x006a, 0x4034,
0x006c, 0x4033, 0x006d, 0x4031, 0x006f, 0x402f, 0x0072, 0x401e,
0x0083, 0x401c, 0x0085, 0x4019, 0x0088, 0x4017, 0x008b, 0x4014,
0x008d, 0x4012, 0x0090, 0x400f, 0x0095, 0x400a, 0x06c5,
}
};

Expand Down
Loading

0 comments on commit 7ebc26c

Please sign in to comment.