diff --git a/.gitignore b/.gitignore index 05165e5..44f1b49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,13 @@ /doc/ +/example/**/obj/ /example/**/bin/ +/obj/ /lib/ /nuvoton-sdk/ /src/startup/evicsdk_tag.s *.o +*.d *.a *.map *.lst diff --git a/Makefile b/Makefile index 4de8807..054ad42 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ include $(EVICSDK)/make/Helper.mk include $(EVICSDK)/make/Common.mk +include $(EVICSDK)/make/Device.mk # Output targets. TARGET_SDK := libevicsdk @@ -132,7 +133,8 @@ __get-sdktag = evic-sdk-$(or $(strip $(shell \ $(if $(EVICSDK_MAKE_DEBUG),$(info SDK tag: $(get-sdktag))) # All objects, excluding debug-only objects. -OBJS_ALL := $(OBJS_SDK) $(OBJS_NUVO) $(OBJS_CRT0) +OBJS_ALL := $(OBJS_SDK) $(OBJS_NUVO) $(OBJS_CRT0) \ + $(call tmpl-flavor,devobjs-tmpl) $(call tmpl-flavor,devobjs-crt0-tmpl) # All debug-only objects. OBJS_ALL_DBG := $(OBJS_CRT0_DBG) @@ -190,13 +192,15 @@ $(lib-all): | $$(@D) $(AR) -rc $(call fixpath-bu,$@) $(call fixpath-bu,$^)) # Build SDK objects for SDK library. -$(sdk-all): $$(call tmpl-build,objs-tmpl,$$(OBJS_SDK)) +$(sdk-all): $$(call tmpl-build,objs-tmpl,$$(OBJS_SDK) \ + $$(call tmpl-build,devobjs-tmpl)) # Build Nuvoton SDK objects for Nuvoton SDK library. $(nuvo-all): $$(call tmpl-build,objs-tmpl,$$(OBJS_NUVO)) # Rule to link crt0 objects into a partially linked object. -$(crt0-all): $$(call tmpl-build,objs-tmpl,$$(OBJS_CRT0)) | $$(@D) +$(crt0-all): $$(call tmpl-build,objs-tmpl,$$(OBJS_CRT0) \ + $$(call tmpl-build,devobjs-crt0-tmpl)) | $$(@D) $(call info-cmd,LNK) @$(call trace, \ $(LD) -r $(call fixpath-bu,$^) -o $(call fixpath-bu,$@)) diff --git a/README.md b/README.md index e104fec..c4b4487 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ flavor. **Supported devices:** - `evic`: Joyetech eVic VTC Mini +- `vtwom`: Joyetech eVic VTwo Mini - `all`: all of the above **Build flavors:** diff --git a/device/evic/Device.mk b/device/evic/Device.mk new file mode 100644 index 0000000..e0aabd6 --- /dev/null +++ b/device/evic/Device.mk @@ -0,0 +1,27 @@ +# This file is part of eVic SDK. +# +# eVic SDK is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# eVic SDK is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with eVic SDK. If not, see . +# +# Copyright (C) 2016 ReservedField + +ifndef __evicsdk_make_device_evic_inc +__evicsdk_make_device_evic_inc := 1 + +include $(EVICSDK)/make/Device.mk + +$(call add-device,evic, \ + device/evic/src/Device.o, \ + device/evic/src/startup.o) + +endif # __evicsdk_make_device_evic_inc diff --git a/device/evic/include/Device.h b/device/evic/include/Device.h new file mode 100644 index 0000000..894f664 --- /dev/null +++ b/device/evic/include/Device.h @@ -0,0 +1,26 @@ +/* + * This file is part of eVic SDK. + * + * eVic SDK is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * eVic SDK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eVic SDK. If not, see . + * + * Copyright (C) 2016 ReservedField + */ + +#ifndef EVICSDK_DEVICE_EVIC_H +#define EVICSDK_DEVICE_EVIC_H + +#define DEVICE_EVIC +#define DEVICE_ADC_MODULE_VBAT 0x12 + +#endif diff --git a/device/evic/src/Device.c b/device/evic/src/Device.c new file mode 100644 index 0000000..150c27d --- /dev/null +++ b/device/evic/src/Device.c @@ -0,0 +1,57 @@ +/* + * This file is part of eVic SDK. + * + * eVic SDK is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * eVic SDK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eVic SDK. If not, see . + * + * Copyright (C) 2016 ReservedField + */ + +#include +#include +#include + +Display_Type_t Device_GetDisplayType() { + switch(gSysInfo.hwVersion) { + case 102: + case 103: + case 106: + case 108: + case 109: + case 111: + return DISPLAY_SSD1327; + default: + return DISPLAY_SSD1306; + } +} + +uint8_t Device_GetAtomizerShunt() { + switch(gSysInfo.hwVersion) { + case 101: + case 108: + return 125; + case 103: + case 104: + case 105: + case 106: + return 110; + case 107: + case 109: + return 120; + case 110: + case 111: + return 105; + default: + return 115; + } +} diff --git a/device/evic/src/startup.s b/device/evic/src/startup.s new file mode 100644 index 0000000..a8edc1f --- /dev/null +++ b/device/evic/src/startup.s @@ -0,0 +1,24 @@ +@ This file is part of eVic SDK. +@ +@ eVic SDK is free software: you can redistribute it and/or modify +@ it under the terms of the GNU General Public License as published by +@ the Free Software Foundation, either version 3 of the License, or +@ (at your option) any later version. +@ +@ eVic SDK is distributed in the hope that it will be useful, +@ but WITHOUT ANY WARRANTY; without even the implied warranty of +@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +@ GNU General Public License for more details. +@ +@ You should have received a copy of the GNU General Public License +@ along with eVic SDK. If not, see . +@ +@ Copyright (C) 2016 ReservedField + +#include + + .syntax unified + + @ Product ID: E052 + @ Max HW version: 1.11 + DEVICE_INFO E052 111 diff --git a/device/vtwom/Device.mk b/device/vtwom/Device.mk new file mode 100644 index 0000000..52b3967 --- /dev/null +++ b/device/vtwom/Device.mk @@ -0,0 +1,27 @@ +# This file is part of eVic SDK. +# +# eVic SDK is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# eVic SDK is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with eVic SDK. If not, see . +# +# Copyright (C) 2016 ReservedField + +ifndef __evicsdk_make_device_vtwom_inc +__evicsdk_make_device_vtwom_inc := 1 + +include $(EVICSDK)/make/Device.mk + +$(call add-device,vtwom, \ + device/vtwom/src/Device.o, \ + device/vtwom/src/startup.o) + +endif # __evicsdk_make_device_vtwom_inc diff --git a/device/vtwom/include/Device.h b/device/vtwom/include/Device.h new file mode 100644 index 0000000..177c55e --- /dev/null +++ b/device/vtwom/include/Device.h @@ -0,0 +1,26 @@ +/* + * This file is part of eVic SDK. + * + * eVic SDK is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * eVic SDK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eVic SDK. If not, see . + * + * Copyright (C) 2016 ReservedField + */ + +#ifndef EVICSDK_DEVICE_VTWOM_H +#define EVICSDK_DEVICE_VTWOM_H + +#define DEVICE_VTWOM +#define DEVICE_ADC_MODULE_VBAT 0x00 + +#endif diff --git a/device/vtwom/src/Device.c b/device/vtwom/src/Device.c new file mode 100644 index 0000000..f22b228 --- /dev/null +++ b/device/vtwom/src/Device.c @@ -0,0 +1,29 @@ +/* + * This file is part of eVic SDK. + * + * eVic SDK is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * eVic SDK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eVic SDK. If not, see . + * + * Copyright (C) 2016 ReservedField + */ + +#include +#include + +Display_Type_t Device_GetDisplayType() { + return DISPLAY_SSD1306; +} + +uint8_t Device_GetAtomizerShunt() { + return 115; +} diff --git a/device/vtwom/src/startup.s b/device/vtwom/src/startup.s new file mode 100644 index 0000000..8621908 --- /dev/null +++ b/device/vtwom/src/startup.s @@ -0,0 +1,24 @@ +@ This file is part of eVic SDK. +@ +@ eVic SDK is free software: you can redistribute it and/or modify +@ it under the terms of the GNU General Public License as published by +@ the Free Software Foundation, either version 3 of the License, or +@ (at your option) any later version. +@ +@ eVic SDK is distributed in the hope that it will be useful, +@ but WITHOUT ANY WARRANTY; without even the implied warranty of +@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +@ GNU General Public License for more details. +@ +@ You should have received a copy of the GNU General Public License +@ along with eVic SDK. If not, see . +@ +@ Copyright (C) 2016 ReservedField + +#include + + .syntax unified + + @ Product ID: E115 + @ Max HW version: 1.00 + DEVICE_INFO E115 100 diff --git a/include/ADC.h b/include/ADC.h index bf0fa26..9e8329e 100644 --- a/include/ADC.h +++ b/include/ADC.h @@ -21,6 +21,7 @@ #define EVICSDK_ADC_H #include +#include #ifdef __cplusplus extern "C" { @@ -64,7 +65,7 @@ extern "C" { * Battery voltage module. * The battery voltage is read through a 1/2 voltage divider. */ -#define ADC_MODULE_VBAT 0x12 +#define ADC_MODULE_VBAT DEVICE_ADC_MODULE_VBAT /** * Function pointer type for ADC filters. diff --git a/include/Device.h b/include/Device.h new file mode 100644 index 0000000..6769954 --- /dev/null +++ b/include/Device.h @@ -0,0 +1,48 @@ +/* + * This file is part of eVic SDK. + * + * eVic SDK is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * eVic SDK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with eVic SDK. If not, see . + * + * Copyright (C) 2016 ReservedField + */ + +#ifndef EVICSDK_DEVICE_H +#define EVICSDK_DEVICE_H + +#include + +/** + * Defines: + * DEVICE_xxx: check concrete header for name. + * DEVICE_ADC_MODULE_VBAT: battery voltage ADC module. + */ + +/** + * Gets the display controller type for this device. + * + * @return Display type. + */ +Display_Type_t Device_GetDisplayType(); + +/** + * Gets the atomizer shunt resistance. + * + * @return Shunt resistance, in 100ths of a mOhm. + */ +uint8_t Device_GetAtomizerShunt(); + +// Include concrete header +#include_next + +#endif diff --git a/include/asm/Verify.s b/include/asm/Verify.s new file mode 100644 index 0000000..782949e --- /dev/null +++ b/include/asm/Verify.s @@ -0,0 +1,40 @@ +@ This file is part of eVic SDK. +@ +@ eVic SDK is free software: you can redistribute it and/or modify +@ it under the terms of the GNU General Public License as published by +@ the Free Software Foundation, either version 3 of the License, or +@ (at your option) any later version. +@ +@ eVic SDK is distributed in the hope that it will be useful, +@ but WITHOUT ANY WARRANTY; without even the implied warranty of +@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +@ GNU General Public License for more details. +@ +@ You should have received a copy of the GNU General Public License +@ along with eVic SDK. If not, see . +@ +@ Copyright (C) 2016 ReservedField + +#ifndef EVICSDK_ASM_VERIFY_H +#define EVICSDK_ASM_VERIFY_H + + .syntax unified + +@ Generates the verification info for a device. +@ pid : product ID. +@ maxhw: maximum supported hardware version. +@ A.BC is passed as integer ABC. +.macro DEVICE_INFO pid maxhw + .section .verify + .ascii "Joyetech APROM" @ Vendor + .ascii "\pid" @ Product ID + @ Maximum supported hardware version + .byte \maxhw / 100 + .byte \maxhw % 100 / 10 + .byte \maxhw % 10 + @ Vendor string must start at least 26 bytes from end of file + @ PID string must start at least 9 bytes from end of file + .space 5 +.endm + +#endif diff --git a/make/Base.mk b/make/Base.mk index 7ac670a..22f572e 100644 --- a/make/Base.mk +++ b/make/Base.mk @@ -21,6 +21,7 @@ # INCDIRS: include directories. # INCDIRS_C: include directories (C only). # INCDIRS_CXX: include directories (C++ only). +# INCDIRS_AS: include directories (ASM only). # LIBDIRS: library directories. # CFLAGS: C compiler flags. # CXXFLAGS: C++ compiler flags. diff --git a/make/Common.mk b/make/Common.mk index 50961dd..a822456 100644 --- a/make/Common.mk +++ b/make/Common.mk @@ -125,15 +125,18 @@ endif INCDIRS_CXX += $(__INCDIRS_GCC_CXX_UNFIX) endif -# Add include directories for SDKs to INCDIRS. +# Add include directories for SDKs. INCDIRS += \ $(NUVOSDK)/CMSIS/Include \ $(NUVOSDK)/Device/Nuvoton/M451Series/Include \ $(NUVOSDK)/StdDriver/inc \ $(EVICSDK)/include +INCDIRS_AS += \ + $(EVICSDK)/include/asm # Cache all needed paths for fixpath. -$(call fixpath-cache,$(INCDIRS) $(INCDIRS_C) $(INCDIRS_CXX)) +$(call fixpath-cache,$(INCDIRS) $(INCDIRS_C) $(INCDIRS_CXX) $(INCDIRS_AS) \ + $(call tmpl-all,devincs-tmpl)) # Gets the compiler flags for the specified include paths. # Argument 1: list of include paths. @@ -156,8 +159,10 @@ ifndef EVICSDK_FPU_DISABLE endif __CFLAGS_INCDIRS := $(call get-incflags,$(INCDIRS_C)) __CXXFLAGS_INCDIRS := $(call get-incflags,$(INCDIRS_CXX)) +__ASFLAGS_INCDIRS := $(call get-incflags,$(INCDIRS_AS)) CFLAGS += $(__CFLAGS_INCDIRS) $(__CC_FLAGS) CXXFLAGS += $(__CXXFLAGS_INCDIRS) $(__CC_FLAGS) -fno-exceptions -fno-rtti +ASFLAGS += $(__ASFLAGS_INCDIRS) -MMD __EXTRA_FLAGS_DBG := -g # Set up toolchain tool names. CC is already set. @@ -292,18 +297,20 @@ define compile-rules $3: %.c $$(call info-cmd,CC) @$$(call trace, \ - $$(CC) $$(CPUFLAGS) $$(CFLAGS) \ + $$(CC) $$(CPUFLAGS) $$(CFLAGS) $$(__DEVICE_INCFLAGS) \ -c $$(call fixpath-cc,$$<) -o $$(call fixpath-cc,$$@)) $3: %.cpp $$(call info-cmd,CXX) @$$(call trace, \ - $$(CXX) $$(CPUFLAGS) $$(CXXFLAGS) \ + $$(CXX) $$(CPUFLAGS) $$(CXXFLAGS) $$(__DEVICE_INCFLAGS) \ -c $$(call fixpath-cc,$$<) -o $$(call fixpath-cc,$$@)) $3: %.s $$(call info-cmd,AS) @$$(call trace, \ $$(AS) $$(CPUFLAGS) $$(ASFLAGS) -c -x assembler-with-cpp \ $$(call fixpath-cc,$$<) -o $$(call fixpath-cc,$$@)) + +$3: __DEVICE_INCFLAGS := $(call get-incflags,$(call devincs-tmpl,$1,$2)) endef # Compilation rules for all object targets. diff --git a/make/Device.mk b/make/Device.mk index 24b8835..e5f1fc1 100644 --- a/make/Device.mk +++ b/make/Device.mk @@ -15,10 +15,27 @@ # # Copyright (C) 2016 ReservedField -ifndef __evicsdk_make_devices_inc -__evicsdk_make_devices_inc := 1 +ifndef __evicsdk_make_device_inc +__evicsdk_make_device_inc := 1 -# Supported devices list. -DEVICES := evic +# Supported devices list. Will be filled in by add-device. +DEVICES := -endif # __evicsdk_make_devices_inc +# Registers a new device. +# Argument 1: device name. +# Argument 2: object list. +# Argument 3: crt0 object list. +add-device = $(eval DEVICES += $1)$(eval \ + __device-objs-$(strip $1) := $2)$(eval \ + __device-objs-crt0-$(strip $1) := $3) + +# Extra device objects template. Flavor is ignored. +devobjs-tmpl = $(__device-objs-$1) +# Extra device crt0 objects template. Flavor is ignored. +devobjs-crt0-tmpl = $(__device-objs-crt0-$1) +# Device include path template. Flavor is ignored. +devincs-tmpl = $(EVICSDK)/device/$1/include + +include $(wildcard $(EVICSDK)/device/*/Device.mk) + +endif # __evicsdk_make_device_inc diff --git a/src/atomizer/Atomizer.c b/src/atomizer/Atomizer.c index 65d4899..29fd13f 100755 --- a/src/atomizer/Atomizer.c +++ b/src/atomizer/Atomizer.c @@ -26,6 +26,7 @@ #include #include #include +#include /** * \file @@ -203,7 +204,7 @@ static volatile Atomizer_ConverterState_t Atomizer_curState = POWEROFF; /** * Shunt resistor value, in 100ths of a mOhm. - * Depends on hardware version. + * Device-specific. */ static uint8_t Atomizer_shuntRes; @@ -661,32 +662,7 @@ static void Atomizer_NegativeFeedback(uint32_t unused) { } void Atomizer_Init() { - // Select shunt value based on hardware version - switch(gSysInfo.hwVersion) { - case 101: - case 108: - Atomizer_shuntRes = 125; - break; - case 103: - case 104: - case 105: - case 106: - Atomizer_shuntRes = 110; - break; - case 107: - case 109: - Atomizer_shuntRes = 120; - break; - case 110: - case 111: - Atomizer_shuntRes = 105; - break; - case 100: - case 102: - default: - Atomizer_shuntRes = 115; - break; - } + Atomizer_shuntRes = Device_GetAtomizerShunt(); // Calculate overcurrent threshold Atomizer_adcOverCurrent = ATOMIZER_ADCINV_CURRENT(ATOMIZER_CURRENT_MAX); diff --git a/src/display/Display.c b/src/display/Display.c index efe70be..c181b02 100644 --- a/src/display/Display.c +++ b/src/display/Display.c @@ -40,6 +40,7 @@ #include #include #include +#include /** * Global framebuffer. @@ -47,7 +48,7 @@ static uint8_t Display_framebuf[DISPLAY_FRAMEBUFFER_SIZE]; /** - * Display type. Depends on hardware version. + * Display type (device-specific). */ static Display_Type_t Display_type; @@ -99,19 +100,7 @@ void Display_Init() { asm volatile ("udf"); } - switch(gSysInfo.hwVersion) { - case 102: - case 103: - case 106: - case 108: - case 109: - case 111: - Display_type = DISPLAY_SSD1327; - break; - default: - Display_type = DISPLAY_SSD1306; - break; - } + Display_type = Device_GetDisplayType(); Display_ClearUnlocked(); Display_SSD_Init(); diff --git a/src/startup/startup.s b/src/startup/startup.s index 8a07d0a..c2da5be 100755 --- a/src/startup/startup.s +++ b/src/startup/startup.s @@ -17,18 +17,6 @@ .syntax unified - @ Verification strings - .section .verify - .ascii "Joyetech APROM" @ Vendor - .ascii "E052" @ Device (eVic VTC Mini) - @ Maximum supported hardware version (A.BC) - .byte 0x01 @ A - .byte 0x01 @ B - .byte 0x01 @ C - @ Vendor string must start at least 26 bytes from end of file - @ Device string must start at least 9 bytes from end of file - .space 5 - .section .stack .align 3 .ifndef Stack_Size