Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TS101 support. #19

Open
wants to merge 1 commit into
base: mainline
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
GIT_VERSION := $(shell git describe --abbrev=8 --dirty --always --tags)

build_type ?= runtime
model ?= unknown
model ?= TS101

ifeq ($(build_type), runtime)
ifeq ($(model), S60)
ifeq ($(model), TS101)
VECTOR_TABLE_OFFSET := 0x8000
else ifeq ($(model), MHP30)
VECTOR_TABLE_OFFSET := 0x8000
else ifeq ($(model), S60)
VECTOR_TABLE_OFFSET := 0x4400
SRC_LD = src/stm32f103_runtime_s60.ld
else
# For MHP30 override the runtime to offset to 32k
ifeq ($(model),"MHP30")
VECTOR_TABLE_OFFSET := 0x8000
SRC_LD = stm32f103_32k_runtime.ld
else

VECTOR_TABLE_OFFSET := 0x4000
SRC_LD = src/stm32f103_runtime.ld
endif
VECTOR_TABLE_OFFSET := 0x4000
endif
BIN = runtime

else
else ifeq ($(build_type), bootloader)
VECTOR_TABLE_OFFSET := 0x0000
SRC_LD = src/stm32f103.ld
BIN = bootloader

endif

SRC_LD = src/stm32f103.ld

BIN = ${build_type}_${model}

INC = -I src

Expand All @@ -43,13 +35,14 @@ include cm-makefile/config.mk
include cm-makefile/rules.mk
include cm-makefile/jlink.mk

WARNFLAGS += -Wno-undef -Wno-conversion -Wall -pedantic -Werror
LDFLAGS += -Wl,--defsym=__BOOTLDR_SIZE__=$(VECTOR_TABLE_OFFSET)

WARNFLAGS += -Wno-undef -Wno-conversion -Wall -pedantic -Werror

OPTFLAGS = -Os -flto -finline-small-functions \
-findirect-inlining -fdiagnostics-color \
-ffunction-sections -fdata-sections -Wno-overlength-strings -ggdb -nostartfiles


ARCHFLAGS = -mcpu=cortex-m3 -mthumb -DSTM32F1 -std=c11
DBGFLAGS =
ARCHFLAGS = -mcpu=cortex-m3 -mthumb -DSTM32F1 -std=c11
DBGFLAGS =

12 changes: 11 additions & 1 deletion build_all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
!# bin/sh

make clean
make -j build_type=bootloader model=TS100
rm -rf build/*.o build/*.d
make -j build_type=runtime model=TS100
Expand All @@ -20,3 +19,14 @@ make -j build_type=bootloader model=MHP30
rm -rf build/*.o build/*.d
make -j build_type=runtime model=MHP30
rm -rf build/*.o build/*.d

make -j build_type=bootloader model=S60
rm -rf build/*.o build/*.d
make -j build_type=runtime model=S60
rm -rf build/*.o build/*.d

make -j build_type=bootloader model=TS101
rm -rf build/*.o build/*.d
make -j build_type=runtime model=TS101
rm -rf build/*.o build/*.d

2 changes: 1 addition & 1 deletion cm-makefile/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $(BUILD_DIR)/$(BIN).dfu: $(BUILD_DIR)/$(BIN).hex
.PHONY: clean
clean:
rm -f $(OUTPUTS)
rm -f $(BUILD_DIR)/$(BIN).map $(BUILD_DIR)/*.o
rm -f $(BUILD_DIR)/$(BIN).map $(BUILD_DIR)/*.o $(BUILD_DIR)/*.d

.PHONY: distclean
distclean: $(DEPS_CLEAN) clean
Expand Down
114 changes: 67 additions & 47 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
#define ENABLE_WATCHDOG 26

#if VECTOR_TABLE_OFFSET != 0
#define SHOW_HASH
#define HASH_REGION_START FLASH_BASE_ADDR
#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB))
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR)
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define RUNTIME_MODE
#define SHOW_HASH
#define HASH_REGION_START FLASH_BASE_ADDR
#define HASH_REGION_END (FLASH_BASE_ADDR + (1024 * FLASH_BOOTLDR_SIZE_KB))
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR)
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define RUNTIME_MODE
#else
#define BOOTLOADER_MODE
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024))
#define BOOTLOADER_MODE
#define DFU_VALID_FLASH_START (FLASH_BASE_ADDR + (FLASH_BOOTLDR_SIZE_KB * 1024))
#define DFU_VALID_FLASH_END (FLASH_BASE_ADDR + (FLASH_BOOTLDR_PAYLOAD_SIZE_KB * 1024))
// In DFU mode, we use button to enter

#define ENABLE_GPIO_DFU_BOOT
Expand All @@ -29,48 +29,68 @@
// Per device config

#ifdef MODEL_TS100
#define GPIO_DFU_BOOT_PORT GPIOA
#define GPIO_DFU_BOOT_PIN 9
#define OLED_RESET_Pin 8
#define OLED_RESET_GPIO_Port GPIOA
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 16
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112
#define GPIO_DFU_BOOT_PORT GPIOA
#define GPIO_DFU_BOOT_PIN 9
#define OLED_RESET_Pin 8
#define OLED_RESET_GPIO_Port GPIOA
#define SCL_Pin 6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 16
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112
#elif MODEL_TS101
#define GPIO_DFU_BOOT_PORT GPIOA
#define GPIO_DFU_BOOT_PIN 8
#define OLED_RESET_Pin 7
#define OLED_RESET_GPIO_Port GPIOA
#define SCL_Pin 0
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 1
#define SDA_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 32
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 96
#elif MODEL_S60
#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 0
#define GPIO_DP_PULLUP_PORT GPIOA
#define GPIO_DP_PULLUP_PIN 8
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 17
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 111

#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 0
#define GPIO_DP_PULLUP_PORT GPIOA
#define GPIO_DP_PULLUP_PIN 8
#define SCL_Pin 6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 17
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 111
#elif MODEL_TS80 || MODEL_TS80P
#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 1
#define OLED_RESET_Pin 15
#define OLED_RESET_GPIO_Port GPIOA
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 16
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112
#define OLED_FLIP

#define GPIO_DFU_BOOT_PORT GPIOB
#define GPIO_DFU_BOOT_PIN 1
#define OLED_RESET_Pin 15
#define OLED_RESET_GPIO_Port GPIOA
#define SCL_Pin 6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 16
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 112
#elif MODEL_MHP30
#define GPIO_DFU_BOOT_PORT GPIOA
#define GPIO_DFU_BOOT_PIN 10
#define OLED_RESET_Pin 4
#define OLED_RESET_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 32
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 96

#define GPIO_DFU_BOOT_PORT GPIOA
#define GPIO_DFU_BOOT_PIN 10
#define OLED_RESET_Pin 4
#define OLED_RESET_GPIO_Port GPIOB
#define SCL_Pin 6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB
#define FLASH_SIZE_KB 128
#define FLASH_BOOTLDR_SIZE_KB 32
#define FLASH_BOOTLDR_PAYLOAD_SIZE_KB 96
#else
#error model not defined, use model= on makefile path
#error model not defined, use model= on makefile path
#endif
// Common for all models
#define SCL_Pin 6
#define SCL_GPIO_Port GPIOB
#define SDA_Pin 7
#define SDA_GPIO_Port GPIOB

#endif

92 changes: 39 additions & 53 deletions src/oled.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,55 @@

uint8_t oled_init_array[] = {
// Every line is a pair of init terms
0x80, 0xAE, /*Display off*/
0x80, 0xD5, /*Set display clock divide ratio / osc freq*/
0x80, 0x52, /*Divide ratios*/
0x80, 0xA8, /*Set Multiplex Ratio*/
0x80, OLED_HEIGHT - 1, /*Vertical size - 1*/
#ifdef OLED_FLIP
0x80, 0xC8, /*Set COM Scan direction backwards*/
#else
0x80, 0xC0, /*Set COM Scan direction*/
#endif
0x80, 0xD2, /*Set vertical Display offset*/
0x80, 0x00, /*0 Offset*/
0x80, 0x40, /*Set Display start line to 0*/
0x80, OLED_SEGMENT_MAP, /*Set Segment remap to backwards*/
0x80, 0x8D, /*Charge Pump*/
0x80, 0x14, /*Charge Pump settings*/
0x80, 0xDA, /*Set VCOM Pins hardware config*/
0x80, OLED_VCOM_LAYOUT, /*Combination 2 for 16 high; 0x12 for 32 high*/
0x80, 0x81, /*Brightness*/
0x80, 0x7F, /*FF == brightest, 0 == dimmest*/
0x80, 0xD9, /*Set pre-charge period*/
0x80, 0x22, /*Pre charge period*/
0x80, 0xDB, /*Adjust VCOMH regulator ouput*/
0x80, 0x30, /*VCOM level*/
0x80, 0xA4, /*Enable the display GDDR*/
0x80, 0XA6, /*Normal display*/
0x80, 0x20, /*Memory Mode*/
0x80, 0x00, /*Wrap memory*/
0x80, 0xAF, /*Display on*/

0x80, 0xAE, // Display off
0x80, 0xD5, // Set display clock divide ratio / osc freq
0x80, 0x52, // Divide ratios
0x80, 0xA8, // Set Multiplex Ratio
0x80, OLED_HEIGHT - 1, // Vertical size - 1
0x80, OLED_VCOM_SCAN, // Set COM Scan direction
0x80, 0xD2, // Set vertical Display offset
0x80, 0x00, // 0 Offset
0x80, 0x40, // Set Display start line to 0
0x80, OLED_SEGMENT_MAP, // Set Segment remap to backwards
0x80, 0x8D, // Charge Pump
0x80, 0x14, // Charge Pump settings
0x80, 0xDA, // Set VCOM Pins hardware config
0x80, OLED_VCOM_LAYOUT, // Combination 2 for 16 high; 0x12 for 32 high
0x80, 0x81, // Brightness
0x80, 0x7F, // FF == brightest, 0 == dimmest
0x80, 0xD9, // Set pre-charge period
0x80, 0x22, // Pre charge period
0x80, 0xDB, // Adjust VCOMH regulator ouput
0x80, 0x30, // VCOM level
0x80, 0xA4, // Enable the display GDDR
0x80, 0xA6, // Normal display
0x80, 0x20, // Memory Mode
0x80, 0x00, // Wrap memory
0x80, 0xAF, // Display on
};

const uint8_t REFRESH_COMMANDS[] = {
// Set display ON:
0x80,
0xAF, // cmd

0x80, 0xAF, // cmd
// Set column address:
// A[6:0] - Column start address = 0x20
// B[6:0] - Column end address = 0x7F
0x80, //
0x21, // cmd
0x80, // Data
OLED_GRAM_START, // Start
0x80, // Data
OLED_GRAM_END, // End
#ifdef OLED_FLIP
// Set COM output scan direction (reverse mode, COM[N-1] to COM0)
0x80, 0xC8,
#else
// Set COM output scan direction (normal mode, COM0 to COM[N-1])
0x80, 0xC0,
#endif
0x80, 0x21, // cmd
0x80, OLED_GRAM_START, // Data Start
0x80, OLED_GRAM_END, // Data End
0x80, OLED_VCOM_SCAN,
// Set page address:
// A[2:0] - Page start address = 0
// B[2:0] - Page end address = 1
0x80,
0x22, // cmd
0x80,
0x00, // A
0x80,
(OLED_HEIGHT / 8), // B

0x80, 0x22, // cmd
0x80, 0x00, // A
0x80, OLED_HEIGHT/8, // B
};

void Data_Command(uint16_t len, const uint8_t *ptr);
void OLED_DrawChar(char c, uint8_t x, const uint8_t row);
void Set_ShowPos(uint8_t x, uint8_t y);

void oled_init(void) {
#ifdef OLED_RESET_GPIO_Port
rcc_gpio_enable(OLED_RESET_GPIO_Port);
Expand All @@ -99,6 +80,7 @@ void oled_init(void) {
}
// init should be done now :)
}

uint8_t displayBuffer[(OLED_HEIGHT / 8) * OLED_WIDTH];
uint8_t OLEDOnOffState = 0; // Used to lock out so we dont send it too often

Expand All @@ -121,11 +103,13 @@ void Data_Command(uint16_t length, const uint8_t *data) {
}
i2c_write_bulk(DEVICEADDR_OLED, length, tx_data);
}

// This causes us to write out the buffered screen data to the display
void oled_Refresh() {
i2c_write_bulk(DEVICEADDR_OLED, sizeof(REFRESH_COMMANDS), REFRESH_COMMANDS);
Data_Command((OLED_HEIGHT / 8) * OLED_WIDTH, displayBuffer);
}

/*******************************************************************************
Function:Set_ShowPos
Description:Set the current position in GRAM that we are drawing to
Expand Down Expand Up @@ -179,6 +163,7 @@ void OLED_DrawString(const char *string, const uint8_t row) {
string++;
}
}

/*
* Draw a char onscreen at letter index x
*/
Expand All @@ -204,3 +189,4 @@ void OLED_DrawChar(char c, uint8_t x, const uint8_t row) {

oled_DrawArea(x, row * 8, FONT_WIDTH, FONT_HEIGHT, (uint8_t *)ptr);
}

Loading