From 7d0af3fc4c117f8bc0b299cbe9306f47f5ed1c1c Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 11 Oct 2018 14:44:56 +1100 Subject: [PATCH] TS80 Support Stage 1 (#365) * Estimated pinout into the ioc file * Fix Atollic paths to be somewhat more portable * Add make command * Add rough calls to ADC2 [untested] * Using dual ADC injected modes * Start both ADCs * Move some IRQ's to ram exec * Stabilize PID a bit more * Add in ideas for tip type selection * Update peripheral setup to support TS80 * Add tiptype formula / settings struct * Add function ids to the settings menu * Rough tip selection * Rough out new cal routine for simple tips * Hardware test is fairly close for first pass * Add Simple calibration case [UNTESTED] This adds the calibration option that uses boiling water to the calibration menu. This is untested, and may need gain adjustments before use. * [Feat] Add some QC testing code * Typo fix * Add double button press handler for different rising times * Add hook for jump to sleep mode * QC for 9V Works! * Rough out QC handler, trim out old menu help text thats useless * QC 9V working... Static all the things (Low on ROM)! * Static all I2C to save space * Move QC negotiation into background task so it doesnt block the UI * Input V display works, tune ADC * QC 3 steps working * Start tip R measurements * Impliment tip resistance * Fix up the accel position, link in auto QC stages * Fix tip title * Tip type settings, Static OLED * Revert I2C callbacks * Misc Cleanup * Better Gain value, need to investiate offset * Add model warning * Add TS80 Boot Logo (#367) * Add TS80 Boot Logo * Refined * Moved down by 1px * Add in power selection 18/24W * Clean up accelerometer, fix TS100 builds, Fix voltage div cal --- Bootup Logo/Logos/001_TS80.hex | 258 + Bootup Logo/Logos/001_TS80.png | Bin 0 -> 15423 bytes Development Resources/TS80-Bootloader.hex | 515 ++ Development Resources/TS80/TS80.ioc | 348 ++ Translation Editor/make_translation.py | 0 Translation Editor/translation_en.json | 10 +- Translation Editor/translations_def.js | 459 +- .../TS100/HAL_Driver/Inc/stm32f1xx_hal_gpio.h | 13 +- .../TS100/HAL_Driver/Src/stm32f1xx_hal_gpio.c | 15 +- .../TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c | 4353 ++++++++--------- workspace/TS100/Makefile | 7 +- workspace/TS100/inc/FRToSI2C.hpp | 29 +- workspace/TS100/inc/FreeRTOSConfig.h | 8 +- workspace/TS100/inc/LIS2DH12.hpp | 28 +- workspace/TS100/inc/MMA8652FC.hpp | 13 +- workspace/TS100/inc/OLED.hpp | 84 +- workspace/TS100/inc/Settings.h | 59 +- workspace/TS100/inc/Translation.h | 8 +- workspace/TS100/inc/hardware.h | 102 +- workspace/TS100/inc/main.hpp | 34 +- workspace/TS100/src/FRToSI2C.cpp | 139 +- workspace/TS100/src/LIS2DH12.cpp | 14 +- workspace/TS100/src/MMA8652FC.cpp | 57 +- workspace/TS100/src/OLED.cpp | 533 +- workspace/TS100/src/Settings.cpp | 161 +- workspace/TS100/src/Setup.c | 654 ++- workspace/TS100/src/Translation.cpp | 323 +- workspace/TS100/src/gui.cpp | 1315 ++--- workspace/TS100/src/hardware.c | 366 +- workspace/TS100/src/main.cpp | 644 +-- workspace/TS100/src/stm32f1xx_hal_msp.c | 14 +- workspace/TS100/src/syscalls.c | 17 +- workspace/TS100A/.project | 10 - .../TS100A/.settings/language.settings.xml | 2 +- 34 files changed, 5857 insertions(+), 4735 deletions(-) create mode 100644 Bootup Logo/Logos/001_TS80.hex create mode 100644 Bootup Logo/Logos/001_TS80.png create mode 100644 Development Resources/TS80-Bootloader.hex create mode 100644 Development Resources/TS80/TS80.ioc mode change 100755 => 100644 Translation Editor/make_translation.py diff --git a/Bootup Logo/Logos/001_TS80.hex b/Bootup Logo/Logos/001_TS80.hex new file mode 100644 index 00000000..61939dce --- /dev/null +++ b/Bootup Logo/Logos/001_TS80.hex @@ -0,0 +1,258 @@ +:020000040800F2 +:10F8000055AA0DF07FFFD5AB7DEA7F7E7F7FFF7F1E +:10F81000FFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFF78 +:10F820007F7FBFBFDFBFEFDF0FEFEF0FAFAFAFAF38 +:10F83000EFEFAFAFAFAFAFAF0FEF6FEFAFAFAFAFB8 +:10F84000AFAF2FAFAFAFAFAFAFAF6FAF6FEFAFAF88 +:10F85000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAFB8 +:10F86000EF6FFF1FFDFFFAFDF7FAF7F7F7F7FAF76B +:10F87000FAFAFAFAFAFAFAFAFAFAFAFAFAFAF0FAF2 +:10F88000F7F7EFEFDFEFBFDF80BFBF80AAAAAAAA1A +:10F89000BFBFAAAAAAAAAAAA80BFB0BFADAFAAAA90 +:10F8A000ADAFA2AAADAAAAAFADAAB0AFB0BFAFAF7D +:10F8B000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAF58 +:10F8C000BFB0FFC00000000000000000000000000A +:10F8D0000000000000000000000000000000000028 +:10F8E0000000000000000000000000000000000018 +:10F8F0000000000000000000000000000000000008 +:10F9000000000000000000000000000000000000F7 +:10F9100000000000000000000000000000000000E7 +:10F9200000000000000000000000000000000000D7 +:10F9300000000000000000000000000000000000C7 +:10F9400000000000000000000000000000000000B7 +:10F9500000000000000000000000000000000000A7 +:10F960000000000000000000000000000000000097 +:10F970000000000000000000000000000000000087 +:10F980000000000000000000000000000000000077 +:10F990000000000000000000000000000000000067 +:10F9A0000000000000000000000000000000000057 +:10F9B0000000000000000000000000000000000047 +:10F9C0000000000000000000000000000000000037 +:10F9D0000000000000000000000000000000000027 +:10F9E0000000000000000000000000000000000017 +:10F9F0000000000000000000000000000000000007 +:10FA000000000000000000000000000000000000F6 +:10FA100000000000000000000000000000000000E6 +:10FA200000000000000000000000000000000000D6 +:10FA300000000000000000000000000000000000C6 +:10FA400000000000000000000000000000000000B6 +:10FA500000000000000000000000000000000000A6 +:10FA60000000000000000000000000000000000096 +:10FA70000000000000000000000000000000000086 +:10FA80000000000000000000000000000000000076 +:10FA90000000000000000000000000000000000066 +:10FAA0000000000000000000000000000000000056 +:10FAB0000000000000000000000000000000000046 +:10FAC0000000000000000000000000000000000036 +:10FAD0000000000000000000000000000000000026 +:10FAE0000000000000000000000000000000000016 +:10FAF0000000000000000000000000000000000006 +:10FB000000000000000000000000000000000000F5 +:10FB100000000000000000000000000000000000E5 +:10FB200000000000000000000000000000000000D5 +:10FB300000000000000000000000000000000000C5 +:10FB400000000000000000000000000000000000B5 +:10FB500000000000000000000000000000000000A5 +:10FB60000000000000000000000000000000000095 +:10FB70000000000000000000000000000000000085 +:10FB80000000000000000000000000000000000075 +:10FB90000000000000000000000000000000000065 +:10FBA0000000000000000000000000000000000055 +:10FBB0000000000000000000000000000000000045 +:10FBC0000000000000000000000000000000000035 +:10FBD0000000000000000000000000000000000025 +:10FBE0000000000000000000000000000000000015 +:10FBF0000000000000000000000000000000000005 +:10F8000055AA0DF07FFFD5AB7DEA7F7E7F7FFF7F1E +:10F81000FFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFF78 +:10F820007F7FBFBFDFBFEFDF0FEFEF0FAFAFAFAF38 +:10F83000EFEFAFAFAFAFAFAF0FEF6FEFAFAFAFAFB8 +:10F84000AFAF2FAFAFAFAFAFAFAF6FAF6FEFAFAF88 +:10F85000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAFB8 +:10F86000EF6FFF1FFDFFFAFDF7FAF7F7F7F7FAF76B +:10F87000FAFAFAFAFAFAFAFAFAFAFAFAFAFAF0FAF2 +:10F88000F7F7EFEFDFEFBFDF80BFBF80AAAAAAAA1A +:10F89000BFBFAAAAAAAAAAAA80BFB0BFADAFAAAA90 +:10F8A000ADAFA2AAADAAAAAFADAAB0AFB0BFAFAF7D +:10F8B000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAF58 +:10F8C000BFB0FFC00000000000000000000000000A +:10F8D0000000000000000000000000000000000028 +:10F8E0000000000000000000000000000000000018 +:10F8F0000000000000000000000000000000000008 +:10F9000000000000000000000000000000000000F7 +:10F9100000000000000000000000000000000000E7 +:10F9200000000000000000000000000000000000D7 +:10F9300000000000000000000000000000000000C7 +:10F9400000000000000000000000000000000000B7 +:10F9500000000000000000000000000000000000A7 +:10F960000000000000000000000000000000000097 +:10F970000000000000000000000000000000000087 +:10F980000000000000000000000000000000000077 +:10F990000000000000000000000000000000000067 +:10F9A0000000000000000000000000000000000057 +:10F9B0000000000000000000000000000000000047 +:10F9C0000000000000000000000000000000000037 +:10F9D0000000000000000000000000000000000027 +:10F9E0000000000000000000000000000000000017 +:10F9F0000000000000000000000000000000000007 +:10FA000000000000000000000000000000000000F6 +:10FA100000000000000000000000000000000000E6 +:10FA200000000000000000000000000000000000D6 +:10FA300000000000000000000000000000000000C6 +:10FA400000000000000000000000000000000000B6 +:10FA500000000000000000000000000000000000A6 +:10FA60000000000000000000000000000000000096 +:10FA70000000000000000000000000000000000086 +:10FA80000000000000000000000000000000000076 +:10FA90000000000000000000000000000000000066 +:10FAA0000000000000000000000000000000000056 +:10FAB0000000000000000000000000000000000046 +:10FAC0000000000000000000000000000000000036 +:10FAD0000000000000000000000000000000000026 +:10FAE0000000000000000000000000000000000016 +:10FAF0000000000000000000000000000000000006 +:10FB000000000000000000000000000000000000F5 +:10FB100000000000000000000000000000000000E5 +:10FB200000000000000000000000000000000000D5 +:10FB300000000000000000000000000000000000C5 +:10FB400000000000000000000000000000000000B5 +:10FB500000000000000000000000000000000000A5 +:10FB60000000000000000000000000000000000095 +:10FB70000000000000000000000000000000000085 +:10FB80000000000000000000000000000000000075 +:10FB90000000000000000000000000000000000065 +:10FBA0000000000000000000000000000000000055 +:10FBB0000000000000000000000000000000000045 +:10FBC0000000000000000000000000000000000035 +:10FBD0000000000000000000000000000000000025 +:10FBE0000000000000000000000000000000000015 +:10FBF0000000000000000000000000000000000005 +:10F8000055AA0DF07FFFD5AB7DEA7F7E7F7FFF7F1E +:10F81000FFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFF78 +:10F820007F7FBFBFDFBFEFDF0FEFEF0FAFAFAFAF38 +:10F83000EFEFAFAFAFAFAFAF0FEF6FEFAFAFAFAFB8 +:10F84000AFAF2FAFAFAFAFAFAFAF6FAF6FEFAFAF88 +:10F85000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAFB8 +:10F86000EF6FFF1FFDFFFAFDF7FAF7F7F7F7FAF76B +:10F87000FAFAFAFAFAFAFAFAFAFAFAFAFAFAF0FAF2 +:10F88000F7F7EFEFDFEFBFDF80BFBF80AAAAAAAA1A +:10F89000BFBFAAAAAAAAAAAA80BFB0BFADAFAAAA90 +:10F8A000ADAFA2AAADAAAAAFADAAB0AFB0BFAFAF7D +:10F8B000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAF58 +:10F8C000BFB0FFC00000000000000000000000000A +:10F8D0000000000000000000000000000000000028 +:10F8E0000000000000000000000000000000000018 +:10F8F0000000000000000000000000000000000008 +:10F9000000000000000000000000000000000000F7 +:10F9100000000000000000000000000000000000E7 +:10F9200000000000000000000000000000000000D7 +:10F9300000000000000000000000000000000000C7 +:10F9400000000000000000000000000000000000B7 +:10F9500000000000000000000000000000000000A7 +:10F960000000000000000000000000000000000097 +:10F970000000000000000000000000000000000087 +:10F980000000000000000000000000000000000077 +:10F990000000000000000000000000000000000067 +:10F9A0000000000000000000000000000000000057 +:10F9B0000000000000000000000000000000000047 +:10F9C0000000000000000000000000000000000037 +:10F9D0000000000000000000000000000000000027 +:10F9E0000000000000000000000000000000000017 +:10F9F0000000000000000000000000000000000007 +:10FA000000000000000000000000000000000000F6 +:10FA100000000000000000000000000000000000E6 +:10FA200000000000000000000000000000000000D6 +:10FA300000000000000000000000000000000000C6 +:10FA400000000000000000000000000000000000B6 +:10FA500000000000000000000000000000000000A6 +:10FA60000000000000000000000000000000000096 +:10FA70000000000000000000000000000000000086 +:10FA80000000000000000000000000000000000076 +:10FA90000000000000000000000000000000000066 +:10FAA0000000000000000000000000000000000056 +:10FAB0000000000000000000000000000000000046 +:10FAC0000000000000000000000000000000000036 +:10FAD0000000000000000000000000000000000026 +:10FAE0000000000000000000000000000000000016 +:10FAF0000000000000000000000000000000000006 +:10FB000000000000000000000000000000000000F5 +:10FB100000000000000000000000000000000000E5 +:10FB200000000000000000000000000000000000D5 +:10FB300000000000000000000000000000000000C5 +:10FB400000000000000000000000000000000000B5 +:10FB500000000000000000000000000000000000A5 +:10FB60000000000000000000000000000000000095 +:10FB70000000000000000000000000000000000085 +:10FB80000000000000000000000000000000000075 +:10FB90000000000000000000000000000000000065 +:10FBA0000000000000000000000000000000000055 +:10FBB0000000000000000000000000000000000045 +:10FBC0000000000000000000000000000000000035 +:10FBD0000000000000000000000000000000000025 +:10FBE0000000000000000000000000000000000015 +:10FBF0000000000000000000000000000000000005 +:10F8000055AA0DF07FFFD5AB7DEA7F7E7F7FFF7F1E +:10F81000FFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFF78 +:10F820007F7FBFBFDFBFEFDF0FEFEF0FAFAFAFAF38 +:10F83000EFEFAFAFAFAFAFAF0FEF6FEFAFAFAFAFB8 +:10F84000AFAF2FAFAFAFAFAFAFAF6FAF6FEFAFAF88 +:10F85000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAFB8 +:10F86000EF6FFF1FFDFFFAFDF7FAF7F7F7F7FAF76B +:10F87000FAFAFAFAFAFAFAFAFAFAFAFAFAFAF0FAF2 +:10F88000F7F7EFEFDFEFBFDF80BFBF80AAAAAAAA1A +:10F89000BFBFAAAAAAAAAAAA80BFB0BFADAFAAAA90 +:10F8A000ADAFA2AAADAAAAAFADAAB0AFB0BFAFAF7D +:10F8B000AFAFAFAFAFAFAFAFAFAFAFAFAFAFAFAF58 +:10F8C000BFB0FFC00000000000000000000000000A +:10F8D0000000000000000000000000000000000028 +:10F8E0000000000000000000000000000000000018 +:10F8F0000000000000000000000000000000000008 +:10F9000000000000000000000000000000000000F7 +:10F9100000000000000000000000000000000000E7 +:10F9200000000000000000000000000000000000D7 +:10F9300000000000000000000000000000000000C7 +:10F9400000000000000000000000000000000000B7 +:10F9500000000000000000000000000000000000A7 +:10F960000000000000000000000000000000000097 +:10F970000000000000000000000000000000000087 +:10F980000000000000000000000000000000000077 +:10F990000000000000000000000000000000000067 +:10F9A0000000000000000000000000000000000057 +:10F9B0000000000000000000000000000000000047 +:10F9C0000000000000000000000000000000000037 +:10F9D0000000000000000000000000000000000027 +:10F9E0000000000000000000000000000000000017 +:10F9F0000000000000000000000000000000000007 +:10FA000000000000000000000000000000000000F6 +:10FA100000000000000000000000000000000000E6 +:10FA200000000000000000000000000000000000D6 +:10FA300000000000000000000000000000000000C6 +:10FA400000000000000000000000000000000000B6 +:10FA500000000000000000000000000000000000A6 +:10FA60000000000000000000000000000000000096 +:10FA70000000000000000000000000000000000086 +:10FA80000000000000000000000000000000000076 +:10FA90000000000000000000000000000000000066 +:10FAA0000000000000000000000000000000000056 +:10FAB0000000000000000000000000000000000046 +:10FAC0000000000000000000000000000000000036 +:10FAD0000000000000000000000000000000000026 +:10FAE0000000000000000000000000000000000016 +:10FAF0000000000000000000000000000000000006 +:10FB000000000000000000000000000000000000F5 +:10FB100000000000000000000000000000000000E5 +:10FB200000000000000000000000000000000000D5 +:10FB300000000000000000000000000000000000C5 +:10FB400000000000000000000000000000000000B5 +:10FB500000000000000000000000000000000000A5 +:10FB60000000000000000000000000000000000095 +:10FB70000000000000000000000000000000000085 +:10FB80000000000000000000000000000000000075 +:10FB90000000000000000000000000000000000065 +:10FBA0000000000000000000000000000000000055 +:10FBB0000000000000000000000000000000000045 +:10FBC0000000000000000000000000000000000035 +:10FBD0000000000000000000000000000000000025 +:10FBE0000000000000000000000000000000000015 +:10FBF0000000000000000000000000000000000005 +:00000001FF diff --git a/Bootup Logo/Logos/001_TS80.png b/Bootup Logo/Logos/001_TS80.png new file mode 100644 index 0000000000000000000000000000000000000000..c33228125598f01ab9d4a7c1f1b9c2cc1ad1e96c GIT binary patch literal 15423 zcmeI3Yitx%6o98nNNEBR6Ko>JOco7-%+6!GkD2UlZM&^4u(T-^+7tt`Gk3R>?(Qr* zv+TA+B^XG3U?NGu2T@}T`U8|i;sc`?Kodg*A^t)WjK&8l0S!`#2E4PgkJ;PpO%q7` zb0^uIJ@?#m&OP6`_w4+cr~1}BJiqDgCW@lw_jE`4;e8YQENq+$zb_mazXosfGTlQ4 zMJ+gCeHtboT(Fp;q~qGapg9;_Eh&1+EvtGAxC^NaoJ~=|)Y_C@YO?~;gV8>^L(c-*>-I4U?+MU;(an3sfY7pn7C7F=aw5yOFdQ#&qQvoZ z>2ige;ICj-jZ6KJu2MKCgP#fg#}5F0%_BLc6?pC%!qF4#)v*c$clQ#z_2FKXeD;t^`=sFLmOu27KosPw63Kw zFqQ#qKQQ!MRso$`U@A-MWp8TnYH?~jS(+Kw4hq@~W|qb_D{ck5LP40T)R6_Usb>dt zJsGxlSzj3;-O*v~DnI?edM&N$d1G0SMNO*pu6hFz*#u!|8DMyh;XDJpR}un}$NL~B zNF3*IV$Vc;M0Hh*kD)#UPHN#Kui*6In2Gv;=SP)Ic~)MWa~*zEMT+a$lx&8zl$-!; zCY=bf)j`M1%C3?+^rW7J%K~9fkgYdd*D9hbIcrG6p>R~6hTyhDg;^U@In{WbyEPCDZG&i3>PZ`>4Abd}gyDc&gDZ;(F;P(i0R{-XpW(QcI1^LiF(%*vqR+!~UcoOG z_eQOGb!8>j<>=6L{lpbjRe4{4hlzV)GbV1Y)8TAdpx&$o+qs-{%&~G&tz5jS$O(eX za4P%~eJ~fXCE#bge2nKrS@d}P-f}K=+)NAAtyy&+L&{*)W-ZuUJ6f%KvGHc)tO2aH z5^|OMN~Kf7sg)~OY)_J`SS>rOSf?JSLAGYJx-8U8t5eQdA+Y^B%x8{~9|37x*RWj` zXU*)y(Bo!a&VsfCJWsP}Xtvi{Gt_n@)vhXpQtvp9h z>ywo(b}N5WGrE;t5nm(-0t7D-TzEc+mf%8w;6;K9&j-;GTnG@nNO0l#AX4T@FKy5=YwboE(8c(B)IT=5G}!l0Ktm{7oHEICAbhEc#+`3^Fg!(7Xkz? z5?pvbh?d|&fZ#=f3(p795?lxnyhw22`5;4|sVBgxMZ5S_3s?Jo z+`nPR-^UY;k;q<-`e5RhPwstr^yreupPzHjAI(d@n>hOUp*tI>L%S{?;MdXHcKrO| zUxgDJbGyZ^4T}yRxcdH>cahZ7J2}}ld1bQm&FAhI{(iXGzsfwhZ_lNzo#3%ohW4Fn z9{=j}Ten?me|^rC_rzu0=5LFy&l_HP>OT4#fCF)>{|HgH;v~{ zZvN?X>(@KGE?=Fv@TfYs;o#Kp)_BSRR = GPIO_Pin; + } + else + { + GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U; + } +} void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin); diff --git a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_gpio.c b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_gpio.c index fc080c07..c3238b70 100644 --- a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_gpio.c +++ b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_gpio.c @@ -479,21 +479,8 @@ GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) * @arg GPIO_BIT_SET: to set the port pin * @retval None */ -void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) -{ - /* Check the parameters */ - assert_param(IS_GPIO_PIN(GPIO_Pin)); - assert_param(IS_GPIO_PIN_ACTION(PinState)); +//void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) - if(PinState != GPIO_PIN_RESET) - { - GPIOx->BSRR = GPIO_Pin; - } - else - { - GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U; - } -} /** * @brief Toggles the specified GPIO pin diff --git a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c index 85c34c3f..67f01bf0 100644 --- a/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c +++ b/workspace/TS100/HAL_Driver/Src/stm32f1xx_hal_tim.c @@ -5,7 +5,7 @@ * @version V1.1.1 * @date 12-May-2017 * @brief TIM HAL module driver - * This file provides firmware functions to manage the following + * This file provides firmware functions to manage the following * functionalities of the Timer (TIM) peripheral: * + Time Base Initialization * + Time Base Start @@ -19,11 +19,11 @@ * + Time Input Capture Initialization * + Time Input Capture Channel Configuration * + Time Input Capture Start - * + Time Input Capture Start Interruption + * + Time Input Capture Start Interruption * + Time Input Capture Start DMA * + Time One Pulse Initialization * + Time One Pulse Channel Configuration - * + Time One Pulse Start + * + Time One Pulse Start * + Time Encoder Interface Initialization * + Time Encoder Interface Start * + Time Encoder Interface Start Interruption @@ -37,19 +37,19 @@ ============================================================================== [..] The Timer features include: (#) 16-bit up, down, up/down auto-reload counter. - (#) 16-bit programmable prescaler allowing dividing (also on the fly) the + (#) 16-bit programmable prescaler allowing dividing (also on the fly) the counter clock frequency either by any factor between 1 and 65536. (#) Up to 4 independent channels for: (++) Input Capture (++) Output Compare (++) PWM generation (Edge and Center-aligned Mode) - (++) One-pulse mode output + (++) One-pulse mode output ##### How to use this driver ##### ============================================================================== [..] - (#) Initialize the TIM low level resources by implementing the following functions - depending from feature used : + (#) Initialize the TIM low level resources by implementing the following + functions depending from feature used : (++) Time Base : HAL_TIM_Base_MspInit() (++) Input Capture : HAL_TIM_IC_MspInit() (++) Output Compare : HAL_TIM_OC_MspInit() @@ -60,35 +60,44 @@ (#) Initialize the TIM low level resources : (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE(); (##) TIM pins configuration - (+++) Enable the clock for the TIM GPIOs using the following function: + (+++) Enable the clock for the TIM GPIOs using the following + function: __HAL_RCC_GPIOx_CLK_ENABLE(); - (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); + (+++) Configure these TIM pins in Alternate function mode using + HAL_GPIO_Init(); - (#) The external Clock can be configured, if needed (the default clock is the - internal clock from the APBx), using the following function: - HAL_TIM_ConfigClockSource, the clock configuration should be done before - any start function. + (#) The external Clock can be configured, if needed (the default clock is + the internal clock from the APBx), using the following function: + HAL_TIM_ConfigClockSource, the clock configuration should be done + before any start function. - (#) Configure the TIM in the desired functioning mode using one of the + (#) Configure the TIM in the desired functioning mode using one of the Initialization function of this driver: (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base - (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an - Output Compare signal. - (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a - PWM signal. - (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an - external signal. - (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer - in One Pulse Mode. + (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to + generate an Output Compare signal. + (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to + generate a PWM signal. + (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to + measure an external signal. + (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use + the Timer in One Pulse Mode. (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface. - (#) Activate the TIM peripheral using one of the start functions depending from the feature used: - (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT() - (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT() - (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT() - (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT() - (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT() - (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT(). + (#) Activate the TIM peripheral using one of the start functions depending + from the feature used: + (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), + HAL_TIM_Base_Start_IT() + (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), + HAL_TIM_IC_Start_IT() + (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), + HAL_TIM_OC_Start_IT() + (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), + HAL_TIM_PWM_Start_IT() + (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), + HAL_TIM_OnePulse_Start_IT() + (++) Encoder mode output : HAL_TIM_Encoder_Start(), + HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT(). (#) The DMA Burst is managed with the two following functions: HAL_TIM_DMABurst_WriteStart() @@ -100,26 +109,33 @@ * *

© COPYRIGHT(c) 2016 STMicroelectronics

* - * Redistribution and use in source and binary forms, with or without modification, + * Redistribution and use in source and binary forms, with or without + modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation + * 2. Redistributions in binary form must reproduce the above copyright + notice, + * this list of conditions and the following disclaimer in the + documentation * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors + * 3. Neither the name of STMicroelectronics nor the names of its + contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** @@ -129,13 +145,13 @@ #include "stm32f1xx_hal.h" /** @addtogroup STM32F1xx_HAL_Driver - * @{ - */ + * @{ + */ /** @defgroup TIM TIM - * @brief TIM HAL module driver - * @{ - */ + * @brief TIM HAL module driver + * @{ + */ #ifdef HAL_TIM_MODULE_ENABLED @@ -145,41 +161,45 @@ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /** @defgroup TIM_Private_Functions TIM Private Functions - * @{ - */ + * @{ + */ static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); -static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); -static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter); -static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); -static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter); -static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter); -static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, - uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter); -static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t InputTriggerSource); +static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICFilter); +static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); +static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICFilter); +static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); +static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); +static void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, + uint32_t TIM_ExtTRGPolarity, + uint32_t ExtTRGFilter); +static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource); static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, - TIM_SlaveConfigTypeDef * sSlaveConfig); + TIM_SlaveConfigTypeDef *sSlaveConfig); /** - * @} - */ + * @} + */ -/* Exported functions ---------------------------------------------------------*/ +/* Exported functions + * ---------------------------------------------------------*/ /** @defgroup TIM_Exported_Functions TIM Exported Functions - * @{ - */ + * @{ + */ -/** @defgroup TIM_Exported_Functions_Group1 Time Base functions - * @brief Time Base functions +/** @defgroup TIM_Exported_Functions_Group1 Time Base functions + * @brief Time Base functions * -@verbatim +@verbatim ============================================================================== ##### Time Base functions ##### ============================================================================== @@ -198,16 +218,14 @@ static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, * @{ */ /** - * @brief Initializes the TIM Time base Unit according to the specified - * parameters in the TIM_HandleTypeDef and create the associated handle. - * @param htim : TIM Base handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Time base Unit according to the specified + * parameters in the TIM_HandleTypeDef and create the associated handle. + * @param htim : TIM Base handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) { /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -217,34 +235,32 @@ HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC */ HAL_TIM_Base_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Set the Time Base configuration */ TIM_Base_SetConfig(htim->Instance, &htim->Init); /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } /** - * @brief DeInitializes the TIM Base peripheral - * @param htim : TIM Base handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM Base peripheral + * @param htim : TIM Base handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); @@ -266,12 +282,11 @@ HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM Base MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Base MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -280,12 +295,11 @@ __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM Base MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM Base MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -293,67 +307,63 @@ __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) */ } - /** - * @brief Starts the TIM Base generation. - * @param htim : TIM handle - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) -{ + * @brief Starts the TIM Base generation. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Enable the Peripheral */ __HAL_TIM_ENABLE(htim); /* Change the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; /* Return function status */ return HAL_OK; } /** - * @brief Stops the TIM Base generation. - * @param htim : TIM handle - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) -{ + * @brief Stops the TIM Base generation. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Disable the Peripheral */ __HAL_TIM_DISABLE(htim); /* Change the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; /* Return function status */ return HAL_OK; } /** - * @brief Starts the TIM Base generation in interrupt mode. - * @param htim : TIM handle - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) -{ + * @brief Starts the TIM Base generation in interrupt mode. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); - /* Enable the TIM Update interrupt */ - __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); + /* Enable the TIM Update interrupt */ + __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); - /* Enable the Peripheral */ + /* Enable the Peripheral */ __HAL_TIM_ENABLE(htim); /* Return function status */ @@ -361,12 +371,11 @@ HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) } /** - * @brief Stops the TIM Base generation in interrupt mode. - * @param htim : TIM handle - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) -{ + * @brief Stops the TIM Base generation in interrupt mode. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); /* Disable the TIM Update interrupt */ @@ -380,29 +389,24 @@ HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) } /** - * @brief Starts the TIM Base generation in DMA mode. - * @param htim : TIM handle - * @param pData : The source Buffer address. - * @param Length : The length of data to be transferred from memory to peripheral. - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) -{ + * @brief Starts the TIM Base generation in DMA mode. + * @param htim : TIM handle + * @param pData : The source Buffer address. + * @param Length : The length of data to be transferred from memory to + * peripheral. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, + uint32_t *pData, uint16_t Length) { /* Check the parameters */ assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if((pData == 0U) && (Length > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if ((pData == 0U) && (Length > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } @@ -410,10 +414,11 @@ HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pDat htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, + (uint32_t)&htim->Instance->ARR, Length); /* Enable the TIM Update DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); @@ -426,12 +431,11 @@ HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pDat } /** - * @brief Stops the TIM Base generation in DMA mode. - * @param htim : TIM handle - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) -{ + * @brief Stops the TIM Base generation in DMA mode. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); @@ -449,13 +453,13 @@ HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions - * @brief Time Output Compare functions +/** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions + * @brief Time Output Compare functions * -@verbatim +@verbatim ============================================================================== ##### Time Output Compare functions ##### ============================================================================== @@ -474,16 +478,14 @@ HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) * @{ */ /** - * @brief Initializes the TIM Output Compare according to the specified - * parameters in the TIM_HandleTypeDef and create the associated handle. - * @param htim : TIM Output Compare handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim) -{ + * @brief Initializes the TIM Output Compare according to the specified + * parameters in the TIM_HandleTypeDef and create the associated handle. + * @param htim : TIM Output Compare handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim) { /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -493,38 +495,36 @@ HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim) assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ HAL_TIM_OC_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Init the base time for the Output Compare */ - TIM_Base_SetConfig(htim->Instance, &htim->Init); + TIM_Base_SetConfig(htim->Instance, &htim->Init); /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } /** - * @brief DeInitializes the TIM peripheral - * @param htim : TIM Output Compare handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM peripheral + * @param htim : TIM Output Compare handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); - htim->State = HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Disable the TIM Peripheral Clock */ __HAL_TIM_DISABLE(htim); @@ -542,12 +542,11 @@ HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM Output Compare MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Output Compare MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -556,12 +555,11 @@ __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM Output Compare MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM Output Compare MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -570,26 +568,24 @@ __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) } /** - * @brief Starts the TIM Output Compare signal generation. - * @param htim : TIM Output Compare handle - * @param Channel : TIM Channel to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Output Compare signal generation. + * @param htim : TIM Output Compare handle + * @param Channel : TIM Channel to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); /* Enable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -602,26 +598,24 @@ HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Stops the TIM Output Compare signal generation. - * @param htim : TIM handle - * @param Channel : TIM Channel to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Output Compare signal generation. + * @param htim : TIM handle + * @param Channel : TIM Channel to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); /* Disable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -634,60 +628,50 @@ HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Starts the TIM Output Compare signal generation in interrupt mode. - * @param htim : TIM OC handle - * @param Channel : TIM Channel to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Output Compare signal generation in interrupt mode. + * @param htim : TIM OC handle + * @param Channel : TIM Channel to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Enable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Enable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Enable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Enable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -700,60 +684,50 @@ HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Stops the TIM Output Compare signal generation in interrupt mode. - * @param htim : TIM Output Compare handle - * @param Channel : TIM Channel to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Output Compare signal generation in interrupt mode. + * @param htim : TIM Output Compare handle + * @param Channel : TIM Channel to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -766,113 +740,103 @@ HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Starts the TIM Output Compare signal generation in DMA mode. - * @param htim : TIM Output Compare handle - * @param Channel : TIM Channel to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @param pData : The source Buffer address. - * @param Length : The length of data to be transferred from memory to TIM peripheral - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) -{ + * @brief Starts the TIM Output Compare signal generation in DMA mode. + * @param htim : TIM Output Compare handle + * @param Channel : TIM Channel to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @param pData : The source Buffer address. + * @param Length : The length of data to be transferred from memory to TIM + * peripheral + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel, uint32_t *pData, + uint16_t Length) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if(((uint32_t)pData == 0U) && (Length > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if (((uint32_t)pData == 0U) && (Length > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR1, Length); /* Enable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR2, Length); /* Enable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR3, Length); /* Enable the TIM Capture/Compare 3 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { - /* Set the DMA Period elapsed callback */ + case TIM_CHANNEL_4: { + /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR4, Length); /* Enable the TIM Capture/Compare 4 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -885,60 +849,50 @@ HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Stops the TIM Output Compare signal generation in DMA mode. - * @param htim : TIM Output Compare handle - * @param Channel : TIM Channel to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Output Compare signal generation in DMA mode. + * @param htim : TIM Output Compare handle + * @param Channel : TIM Channel to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Output compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -954,13 +908,13 @@ HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group3 Time PWM functions - * @brief Time PWM functions +/** @defgroup TIM_Exported_Functions_Group3 Time PWM functions + * @brief Time PWM functions * -@verbatim +@verbatim ============================================================================== ##### Time PWM functions ##### ============================================================================== @@ -979,16 +933,14 @@ HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) * @{ */ /** - * @brief Initializes the TIM PWM Time Base according to the specified - * parameters in the TIM_HandleTypeDef and create the associated handle. - * @param htim : TIM handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM PWM Time Base according to the specified + * parameters in the TIM_HandleTypeDef and create the associated handle. + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) { /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -998,34 +950,32 @@ HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ HAL_TIM_PWM_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Init the base time for the PWM */ TIM_Base_SetConfig(htim->Instance, &htim->Init); /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } /** - * @brief DeInitializes the TIM peripheral - * @param htim : TIM handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM peripheral + * @param htim : TIM handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); @@ -1047,12 +997,11 @@ HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM PWM MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM PWM MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -1061,12 +1010,11 @@ __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM PWM MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM PWM MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -1075,26 +1023,24 @@ __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) } /** - * @brief Starts the PWM signal generation. - * @param htim : TIM handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the PWM signal generation. + * @param htim : TIM handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); /* Enable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -1107,26 +1053,24 @@ HAL_StatusTypeDef __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TI } /** - * @brief Stops the PWM signal generation. - * @param htim : TIM handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the PWM signal generation. + * @param htim : TIM handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); /* Disable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -1142,60 +1086,50 @@ HAL_StatusTypeDef __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TI } /** - * @brief Starts the PWM signal generation in interrupt mode. - * @param htim : TIM handle - * @param Channel : TIM Channel to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the PWM signal generation in interrupt mode. + * @param htim : TIM handle + * @param Channel : TIM Channel to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Enable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Enable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Enable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Enable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -1208,60 +1142,50 @@ HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Stops the PWM signal generation in interrupt mode. - * @param htim : TIM handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the PWM signal generation in interrupt mode. + * @param htim : TIM handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -1274,113 +1198,103 @@ HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Starts the TIM PWM signal generation in DMA mode. - * @param htim : TIM handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @param pData : The source Buffer address. - * @param Length : The length of data to be transferred from memory to TIM peripheral - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) -{ + * @brief Starts the TIM PWM signal generation in DMA mode. + * @param htim : TIM handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @param pData : The source Buffer address. + * @param Length : The length of data to be transferred from memory to TIM + * peripheral + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel, uint32_t *pData, + uint16_t Length) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if(((uint32_t)pData == 0U) && (Length > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if (((uint32_t)pData == 0U) && (Length > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR1, Length); /* Enable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR2, Length); /* Enable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR3, Length); /* Enable the TIM Output Capture/Compare 3 request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { - /* Set the DMA Period elapsed callback */ + case TIM_CHANNEL_4: { + /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, + (uint32_t)&htim->Instance->CCR4, Length); /* Enable the TIM Capture/Compare 4 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -1393,60 +1307,50 @@ HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channe } /** - * @brief Stops the TIM PWM signal generation in DMA mode. - * @param htim : TIM handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM PWM signal generation in DMA mode. + * @param htim : TIM handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -1462,13 +1366,13 @@ HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions - * @brief Time Input Capture functions +/** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions + * @brief Time Input Capture functions * -@verbatim +@verbatim ============================================================================== ##### Time Input Capture functions ##### ============================================================================== @@ -1487,16 +1391,15 @@ HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel * @{ */ /** - * @brief Initializes the TIM Input Capture Time base according to the specified - * parameters in the TIM_HandleTypeDef and create the associated handle. - * @param htim : TIM Input Capture handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Input Capture Time base according to the + * specified parameters in the TIM_HandleTypeDef and create the associated + * handle. + * @param htim : TIM Input Capture handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) { /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -1506,34 +1409,32 @@ HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ HAL_TIM_IC_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Init the base time for the input capture */ TIM_Base_SetConfig(htim->Instance, &htim->Init); /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } /** - * @brief DeInitializes the TIM peripheral - * @param htim : TIM Input Capture handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM peripheral + * @param htim : TIM Input Capture handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); @@ -1555,12 +1456,11 @@ HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM Input Capture MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Input Capture MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -1569,12 +1469,11 @@ __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM Input Capture MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM Input Capture MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -1583,18 +1482,17 @@ __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) } /** - * @brief Starts the TIM Input Capture measurement. - * @param htim : TIM Input Capture handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Input Capture measurement. + * @param htim : TIM Input Capture handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); @@ -1609,18 +1507,17 @@ HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Stops the TIM Input Capture measurement. - * @param htim : TIM handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Input Capture measurement. + * @param htim : TIM handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); @@ -1635,53 +1532,44 @@ HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Starts the TIM Input Capture measurement in interrupt mode. - * @param htim : TIM Input Capture handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Input Capture measurement in interrupt mode. + * @param htim : TIM Input Capture handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Enable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Enable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Enable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Enable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Input Capture channel */ TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); @@ -1694,53 +1582,44 @@ HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Stops the TIM Input Capture measurement in interrupt mode. - * @param htim : TIM handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Input Capture measurement in interrupt mode. + * @param htim : TIM handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Input Capture channel */ @@ -1754,108 +1633,103 @@ HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @brief Starts the TIM Input Capture measurement in DMA mode. - * @param htim : TIM Input Capture handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @param pData : The destination Buffer address. - * @param Length : The length of data to be transferred from TIM peripheral to memory. - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) -{ + * @brief Starts the TIM Input Capture measurement in DMA mode. + * @param htim : TIM Input Capture handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @param pData : The destination Buffer address. + * @param Length : The length of data to be transferred from TIM peripheral to + * memory. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel, uint32_t *pData, + uint16_t Length) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if((pData == 0U) && (Length > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if ((pData == 0U) && (Length > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], + (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, + Length); /* Enable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], + (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, + Length); /* Enable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], + (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, + Length); /* Enable the TIM Capture/Compare 3 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], + (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, + Length); /* Enable the TIM Capture/Compare 4 DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Enable the Input Capture channel */ @@ -1869,54 +1743,45 @@ HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Stops the TIM Input Capture measurement in DMA mode. - * @param htim : TIM Input Capture handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Input Capture measurement in DMA mode. + * @param htim : TIM Input Capture handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Disable the TIM Capture/Compare 1 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Disable the TIM Capture/Compare 2 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Disable the TIM Capture/Compare 3 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Disable the TIM Capture/Compare 4 DMA request */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); - } - break; + } break; default: - break; + break; } /* Disable the Input Capture channel */ @@ -1932,13 +1797,13 @@ HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) return HAL_OK; } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions - * @brief Time One Pulse functions +/** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions + * @brief Time One Pulse functions * -@verbatim +@verbatim ============================================================================== ##### Time One Pulse functions ##### ============================================================================== @@ -1957,20 +1822,19 @@ HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) * @{ */ /** - * @brief Initializes the TIM One Pulse Time Base according to the specified - * parameters in the TIM_HandleTypeDef and create the associated handle. - * @param htim : TIM OnePulse handle - * @param OnePulseMode : Select the One pulse mode. - * This parameter can be one of the following values: - * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. - * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) -{ + * @brief Initializes the TIM One Pulse Time Base according to the specified + * parameters in the TIM_HandleTypeDef and create the associated handle. + * @param htim : TIM OnePulse handle + * @param OnePulseMode : Select the One pulse mode. + * This parameter can be one of the following values: + * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. + * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, + uint32_t OnePulseMode) { /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -1981,17 +1845,16 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePul assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); assert_param(IS_TIM_OPM_MODE(OnePulseMode)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ HAL_TIM_OnePulse_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Configure the Time base in the One Pulse Mode */ TIM_Base_SetConfig(htim->Instance, &htim->Init); @@ -2003,18 +1866,17 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePul htim->Instance->CR1 |= OnePulseMode; /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } /** - * @brief DeInitializes the TIM One Pulse - * @param htim : TIM One Pulse handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM One Pulse + * @param htim : TIM One Pulse handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); @@ -2036,12 +1898,11 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM One Pulse MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM One Pulse MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -2050,12 +1911,11 @@ __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM One Pulse MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM One Pulse MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -2064,33 +1924,33 @@ __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) } /** - * @brief Starts the TIM One Pulse signal generation. - * @param htim : TIM One Pulse handle - * @param OutputChannel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) -{ + * @brief Starts the TIM One Pulse signal generation. + * @param htim : TIM One Pulse handle + * @param OutputChannel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, + uint32_t OutputChannel) { /* Prevent unused argument(s) compilation warning */ UNUSED(OutputChannel); - /* Enable the Capture compare and the Input Capture channels - (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) - if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and - if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output - in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together + /* Enable the Capture compare and the Input Capture channels + (in the OPM Mode the two possible channels that can be used are + TIM_CHANNEL_1 and TIM_CHANNEL_2) if TIM_CHANNEL_1 is used as output, the + TIM_CHANNEL_2 will be used as input and if TIM_CHANNEL_1 is used as input, + the TIM_CHANNEL_2 will be used as output in all combinations, the + TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together - No need to enable the counter, it's enabled automatically by hardware + No need to enable the counter, it's enabled automatically by hardware (the counter starts in response to a stimulus and generate a pulse */ TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -2100,30 +1960,30 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t Outpu } /** - * @brief Stops the TIM One Pulse signal generation. - * @param htim : TIM One Pulse handle - * @param OutputChannel : TIM Channels to be disable - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) -{ + * @brief Stops the TIM One Pulse signal generation. + * @param htim : TIM One Pulse handle + * @param OutputChannel : TIM Channels to be disable + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, + uint32_t OutputChannel) { /* Prevent unused argument(s) compilation warning */ UNUSED(OutputChannel); /* Disable the Capture compare and the Input Capture channels - (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) - if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and - if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output - in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ + (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 + and TIM_CHANNEL_2) if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will + be used as input and if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will + be used as output in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 + should be disabled together */ TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } @@ -2136,26 +1996,27 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t Output } /** - * @brief Starts the TIM One Pulse signal generation in interrupt mode. - * @param htim : TIM One Pulse handle - * @param OutputChannel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) -{ + * @brief Starts the TIM One Pulse signal generation in interrupt mode. + * @param htim : TIM One Pulse handle + * @param OutputChannel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, + uint32_t OutputChannel) { /* Prevent unused argument(s) compilation warning */ UNUSED(OutputChannel); - /* Enable the Capture compare and the Input Capture channels - (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) - if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and - if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output - in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together + /* Enable the Capture compare and the Input Capture channels + (in the OPM Mode the two possible channels that can be used are + TIM_CHANNEL_1 and TIM_CHANNEL_2) if TIM_CHANNEL_1 is used as output, the + TIM_CHANNEL_2 will be used as input and if TIM_CHANNEL_1 is used as input, + the TIM_CHANNEL_2 will be used as output in all combinations, the + TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together - No need to enable the counter, it's enabled automatically by hardware + No need to enable the counter, it's enabled automatically by hardware (the counter starts in response to a stimulus and generate a pulse */ /* Enable the TIM Capture/Compare 1 interrupt */ @@ -2167,8 +2028,7 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t Ou TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Enable the main output */ __HAL_TIM_MOE_ENABLE(htim); } @@ -2178,16 +2038,16 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t Ou } /** - * @brief Stops the TIM One Pulse signal generation in interrupt mode. - * @param htim : TIM One Pulse handle - * @param OutputChannel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) -{ + * @brief Stops the TIM One Pulse signal generation in interrupt mode. + * @param htim : TIM One Pulse handle + * @param OutputChannel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, + uint32_t OutputChannel) { /* Prevent unused argument(s) compilation warning */ UNUSED(OutputChannel); @@ -2197,35 +2057,35 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Out /* Disable the TIM Capture/Compare 2 interrupt */ __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); - /* Disable the Capture compare and the Input Capture channels - (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) - if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and - if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output - in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ + /* Disable the Capture compare and the Input Capture channels + (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 + and TIM_CHANNEL_2) if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will + be used as input and if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will + be used as output in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 + should be disabled together */ TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); - if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) - { + if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) { /* Disable the Main Ouput */ __HAL_TIM_MOE_DISABLE(htim); } /* Disable the Peripheral */ - __HAL_TIM_DISABLE(htim); + __HAL_TIM_DISABLE(htim); /* Return function status */ return HAL_OK; } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions - * @brief Time Encoder functions +/** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions + * @brief Time Encoder functions * -@verbatim +@verbatim ============================================================================== ##### Time Encoder functions ##### ============================================================================== @@ -2244,20 +2104,20 @@ HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Out * @{ */ /** - * @brief Initializes the TIM Encoder Interface and create the associated handle. - * @param htim : TIM Encoder Interface handle - * @param sConfig : TIM Encoder Interface configuration structure - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig) -{ + * @brief Initializes the TIM Encoder Interface and create the associated + * handle. + * @param htim : TIM Encoder Interface handle + * @param sConfig : TIM Encoder Interface configuration structure + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, + TIM_Encoder_InitTypeDef *sConfig) { uint32_t tmpsmcr = 0U; uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; /* Check the TIM handle allocation */ - if(htim == NULL) - { + if (htim == NULL) { return HAL_ERROR; } @@ -2276,17 +2136,16 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_Ini assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); - if(htim->State == HAL_TIM_STATE_RESET) - { + if (htim->State == HAL_TIM_STATE_RESET) { /* Allocate lock resource and initialize it */ htim->Lock = HAL_UNLOCKED; - + /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ HAL_TIM_Encoder_MspInit(htim); } /* Set the TIM state */ - htim->State= HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; /* Reset the SMS bits */ htim->Instance->SMCR &= ~TIM_SMCR_SMS; @@ -2310,7 +2169,8 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_Ini tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U)); - /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ + /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and + * filters */ tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U); @@ -2331,19 +2191,17 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_Ini htim->Instance->CCER = tmpccer; /* Initialize the TIM state*/ - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; return HAL_OK; } - /** - * @brief DeInitializes the TIM Encoder interface - * @param htim : TIM Encoder handle - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes the TIM Encoder interface + * @param htim : TIM Encoder handle + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); @@ -2365,12 +2223,11 @@ HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) } /** - * @brief Initializes the TIM Encoder Interface MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) -{ + * @brief Initializes the TIM Encoder Interface MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -2379,12 +2236,11 @@ __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) } /** - * @brief DeInitializes TIM Encoder Interface MSP. - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) -{ + * @brief DeInitializes TIM Encoder Interface MSP. + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -2393,38 +2249,34 @@ __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) } /** - * @brief Starts the TIM Encoder Interface. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Encoder Interface. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Enable the encoder interface channels */ - switch (Channel) - { - case TIM_CHANNEL_1: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); + switch (Channel) { + case TIM_CHANNEL_1: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); break; - } - case TIM_CHANNEL_2: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); + } + case TIM_CHANNEL_2: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); + break; + } + default: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); break; - } - default : - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - break; } } /* Enable the Peripheral */ @@ -2435,39 +2287,36 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channe } /** - * @brief Stops the TIM Encoder Interface. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Encoder Interface. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ - assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); + assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - /* Disable the Input Capture channels 1 and 2 - (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ - switch (Channel) - { - case TIM_CHANNEL_1: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); + /* Disable the Input Capture channels 1 and 2 + (in the EncoderInterface the two possible channels that can be used are + TIM_CHANNEL_1 and TIM_CHANNEL_2) */ + switch (Channel) { + case TIM_CHANNEL_1: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); break; - } - case TIM_CHANNEL_2: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); + } + case TIM_CHANNEL_2: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); + break; + } + default: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); break; - } - default : - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); - break; } } @@ -2479,43 +2328,39 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel } /** - * @brief Starts the TIM Encoder Interface in interrupt mode. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Starts the TIM Encoder Interface in interrupt mode. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Enable the encoder interface channels */ /* Enable the capture compare Interrupts 1 and/or 2 */ - switch (Channel) - { - case TIM_CHANNEL_1: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); - __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); + switch (Channel) { + case TIM_CHANNEL_1: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); + __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); break; - } - case TIM_CHANNEL_2: - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); + } + case TIM_CHANNEL_2: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); + __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); + break; + } + default: { + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); + TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); + __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); + __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); break; - } - default : - { - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); - TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); - __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); - break; } } @@ -2527,38 +2372,34 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Cha } /** - * @brief Stops the TIM Encoder Interface in interrupt mode. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be disabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Encoder Interface in interrupt mode. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be disabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Disable the Input Capture channels 1 and 2 - (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ - if(Channel == TIM_CHANNEL_1) - { + (in the EncoderInterface the two possible channels that can be used are + TIM_CHANNEL_1 and TIM_CHANNEL_2) */ + if (Channel == TIM_CHANNEL_1) { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); /* Disable the capture compare Interrupts 1 */ - __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); - } - else if(Channel == TIM_CHANNEL_2) - { + __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); + } else if (Channel == TIM_CHANNEL_2) { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); /* Disable the capture compare Interrupts 2 */ - __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); - } - else - { + __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); + } else { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); @@ -2578,51 +2419,47 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chan } /** - * @brief Starts the TIM Encoder Interface in DMA mode. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @param pData1 : The destination Buffer address for IC1. - * @param pData2 : The destination Buffer address for IC2. - * @param Length : The length of data to be transferred from TIM peripheral to memory. - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length) -{ + * @brief Starts the TIM Encoder Interface in DMA mode. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @param pData1 : The destination Buffer address for IC1. + * @param pData2 : The destination Buffer address for IC2. + * @param Length : The length of data to be transferred from TIM peripheral to + * memory. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel, uint32_t *pData1, + uint32_t *pData2, uint16_t Length) { /* Check the parameters */ assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if((((pData1 == 0U) || (pData2 == 0U) )) && (Length > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if ((((pData1 == 0U) || (pData2 == 0U))) && (Length > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], + (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, + Length); /* Enable the TIM Input Capture DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); @@ -2632,18 +2469,18 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Ch /* Enable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], + (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, + Length); /* Enable the TIM Input Capture DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); @@ -2653,30 +2490,32 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Ch /* Enable the Capture compare channel */ TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); - } - break; + } break; - case TIM_CHANNEL_ALL: - { + case TIM_CHANNEL_ALL: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], + (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, + Length); /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], + (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, + Length); - /* Enable the Peripheral */ + /* Enable the Peripheral */ __HAL_TIM_ENABLE(htim); /* Enable the Capture compare channel */ @@ -2687,49 +2526,44 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Ch __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); /* Enable the TIM Input Capture DMA request */ __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); - } - break; + } break; default: - break; + break; } /* Return function status */ return HAL_OK; } /** - * @brief Stops the TIM Encoder Interface in DMA mode. - * @param htim : TIM Encoder Interface handle - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected - * @retval HAL status -*/ -HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Stops the TIM Encoder Interface in DMA mode. + * @param htim : TIM Encoder Interface handle + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); /* Disable the Input Capture channels 1 and 2 - (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ - if(Channel == TIM_CHANNEL_1) - { + (in the EncoderInterface the two possible channels that can be used are + TIM_CHANNEL_1 and TIM_CHANNEL_2) */ + if (Channel == TIM_CHANNEL_1) { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); /* Disable the capture compare DMA Request 1 */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); - } - else if(Channel == TIM_CHANNEL_2) - { + } else if (Channel == TIM_CHANNEL_2) { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); /* Disable the capture compare DMA Request 2 */ __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); - } - else - { + } else { TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); @@ -2749,12 +2583,12 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Cha } /** - * @} - */ -/** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management - * @brief IRQ handler management + * @} + */ +/** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management + * @brief IRQ handler management * -@verbatim +@verbatim ============================================================================== ##### IRQ handler management ##### ============================================================================== @@ -2765,29 +2599,24 @@ HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Cha * @{ */ /** - * @brief This function handles TIM interrupts requests. - * @param htim : TIM handle - * @retval None - */ -void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) -{ + * @brief This function handles TIM interrupts requests. + * @param htim : TIM handle + * @retval None + */ +void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) { /* Capture compare 1 event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET) { { __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; /* Input capture event */ - if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U) - { + if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U) { HAL_TIM_IC_CaptureCallback(htim); } /* Output compare event */ - else - { + else { HAL_TIM_OC_DelayElapsedCallback(htim); HAL_TIM_PWM_PulseFinishedCallback(htim); } @@ -2796,20 +2625,16 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 2 event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; /* Input capture event */ - if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) - { + if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) { HAL_TIM_IC_CaptureCallback(htim); } /* Output compare event */ - else - { + else { HAL_TIM_OC_DelayElapsedCallback(htim); HAL_TIM_PWM_PulseFinishedCallback(htim); } @@ -2817,20 +2642,16 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 3 event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; /* Input capture event */ - if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) - { + if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) { HAL_TIM_IC_CaptureCallback(htim); } /* Output compare event */ - else - { + else { HAL_TIM_OC_DelayElapsedCallback(htim); HAL_TIM_PWM_PulseFinishedCallback(htim); } @@ -2838,20 +2659,16 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* Capture compare 4 event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; /* Input capture event */ - if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) - { + if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) { HAL_TIM_IC_CaptureCallback(htim); } /* Output compare event */ - else - { + else { HAL_TIM_OC_DelayElapsedCallback(htim); HAL_TIM_PWM_PulseFinishedCallback(htim); } @@ -2859,37 +2676,29 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } } /* TIM Update event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); HAL_TIM_PeriodElapsedCallback(htim); } } /* TIM Break input event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK); HAL_TIMEx_BreakCallback(htim); } } /* TIM Trigger detection event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); HAL_TIM_TriggerCallback(htim); } } /* TIM commutation event */ - if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) - { - if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) !=RESET) - { + if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET) { __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM); HAL_TIMEx_CommutationCallback(htim); } @@ -2897,13 +2706,13 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) } /** - * @} - */ + * @} + */ /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions - * @brief Peripheral Control functions + * @brief Peripheral Control functions * -@verbatim +@verbatim ============================================================================== ##### Peripheral Control functions ##### ============================================================================== @@ -2920,20 +2729,21 @@ void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) */ /** - * @brief Initializes the TIM Output Compare Channels according to the specified - * parameters in the TIM_OC_InitTypeDef. - * @param htim : TIM Output Compare handle - * @param sConfig : TIM Output Compare configuration structure - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) -{ + * @brief Initializes the TIM Output Compare Channels according to the + * specified parameters in the TIM_OC_InitTypeDef. + * @param htim : TIM Output Compare handle + * @param sConfig : TIM Output Compare configuration structure + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, + TIM_OC_InitTypeDef *sConfig, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CHANNELS(Channel)); assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); @@ -2944,42 +2754,33 @@ HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitT htim->State = HAL_TIM_STATE_BUSY; - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); /* Configure the TIM Channel 1 in Output Compare */ TIM_OC1_SetConfig(htim->Instance, sConfig); - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Configure the TIM Channel 2 in Output Compare */ TIM_OC2_SetConfig(htim->Instance, sConfig); - } - break; + } break; - case TIM_CHANNEL_3: - { - assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); + case TIM_CHANNEL_3: { + assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); /* Configure the TIM Channel 3 in Output Compare */ TIM_OC3_SetConfig(htim->Instance, sConfig); - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); - /* Configure the TIM Channel 4 in Output Compare */ - TIM_OC4_SetConfig(htim->Instance, sConfig); - } - break; + /* Configure the TIM Channel 4 in Output Compare */ + TIM_OC4_SetConfig(htim->Instance, sConfig); + } break; default: - break; + break; } htim->State = HAL_TIM_STATE_READY; @@ -2989,20 +2790,21 @@ HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitT } /** - * @brief Initializes the TIM Input Capture Channels according to the specified - * parameters in the TIM_IC_InitTypeDef. - * @param htim : TIM IC handle - * @param sConfig : TIM Input Capture configuration structure - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel) -{ + * @brief Initializes the TIM Input Capture Channels according to the specified + * parameters in the TIM_IC_InitTypeDef. + * @param htim : TIM IC handle + * @param sConfig : TIM Input Capture configuration structure + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, + TIM_IC_InitTypeDef *sConfig, + uint32_t Channel) { /* Check the parameters */ assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); @@ -3014,28 +2816,21 @@ HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitT htim->State = HAL_TIM_STATE_BUSY; - if (Channel == TIM_CHANNEL_1) - { + if (Channel == TIM_CHANNEL_1) { /* TI1 Configuration */ - TIM_TI1_SetConfig(htim->Instance, - sConfig->ICPolarity, - sConfig->ICSelection, - sConfig->ICFilter); + TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, sConfig->ICSelection, + sConfig->ICFilter); /* Reset the IC1PSC Bits */ htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; /* Set the IC1PSC value */ htim->Instance->CCMR1 |= sConfig->ICPrescaler; - } - else if (Channel == TIM_CHANNEL_2) - { + } else if (Channel == TIM_CHANNEL_2) { /* TI2 Configuration */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - TIM_TI2_SetConfig(htim->Instance, - sConfig->ICPolarity, - sConfig->ICSelection, + TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, sConfig->ICSelection, sConfig->ICFilter); /* Reset the IC2PSC Bits */ @@ -3043,32 +2838,24 @@ HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitT /* Set the IC2PSC value */ htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U); - } - else if (Channel == TIM_CHANNEL_3) - { + } else if (Channel == TIM_CHANNEL_3) { /* TI3 Configuration */ assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); - TIM_TI3_SetConfig(htim->Instance, - sConfig->ICPolarity, - sConfig->ICSelection, - sConfig->ICFilter); + TIM_TI3_SetConfig(htim->Instance, sConfig->ICPolarity, sConfig->ICSelection, + sConfig->ICFilter); /* Reset the IC3PSC Bits */ htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; /* Set the IC3PSC value */ htim->Instance->CCMR2 |= sConfig->ICPrescaler; - } - else - { + } else { /* TI4 Configuration */ assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); - TIM_TI4_SetConfig(htim->Instance, - sConfig->ICPolarity, - sConfig->ICSelection, - sConfig->ICFilter); + TIM_TI4_SetConfig(htim->Instance, sConfig->ICPolarity, sConfig->ICSelection, + sConfig->ICFilter); /* Reset the IC4PSC Bits */ htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; @@ -3085,20 +2872,21 @@ HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitT } /** - * @brief Initializes the TIM PWM channels according to the specified - * parameters in the TIM_OC_InitTypeDef. - * @param htim : TIM handle - * @param sConfig : TIM PWM configuration structure - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @arg TIM_CHANNEL_3: TIM Channel 3 selected - * @arg TIM_CHANNEL_4: TIM Channel 4 selected - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) -{ + * @brief Initializes the TIM PWM channels according to the specified + * parameters in the TIM_OC_InitTypeDef. + * @param htim : TIM handle + * @param sConfig : TIM PWM configuration structure + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @arg TIM_CHANNEL_3: TIM Channel 3 selected + * @arg TIM_CHANNEL_4: TIM Channel 4 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, + TIM_OC_InitTypeDef *sConfig, + uint32_t Channel) { __HAL_LOCK(htim); /* Check the parameters */ @@ -3109,10 +2897,8 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init htim->State = HAL_TIM_STATE_BUSY; - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); /* Configure the Channel 1 in PWM mode */ TIM_OC1_SetConfig(htim->Instance, sConfig); @@ -3123,11 +2909,9 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init /* Configure the Output Fast mode */ htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; htim->Instance->CCMR1 |= sConfig->OCFastMode; - } - break; + } break; - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Configure the Channel 2 in PWM mode */ TIM_OC2_SetConfig(htim->Instance, sConfig); @@ -3138,11 +2922,9 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init /* Configure the Output Fast mode */ htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; htim->Instance->CCMR1 |= sConfig->OCFastMode << 8; - } - break; + } break; - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); /* Configure the Channel 3 in PWM mode */ TIM_OC3_SetConfig(htim->Instance, sConfig); @@ -3150,14 +2932,12 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init /* Set the Preload enable bit for channel3 */ htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; - /* Configure the Output Fast mode */ + /* Configure the Output Fast mode */ htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; htim->Instance->CCMR2 |= sConfig->OCFastMode; - } - break; + } break; - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); /* Configure the Channel 4 in PWM mode */ TIM_OC4_SetConfig(htim->Instance, sConfig); @@ -3165,14 +2945,13 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init /* Set the Preload enable bit for channel4 */ htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; - /* Configure the Output Fast mode */ + /* Configure the Output Fast mode */ htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; htim->Instance->CCMR2 |= sConfig->OCFastMode << 8; - } - break; + } break; default: - break; + break; } htim->State = HAL_TIM_STATE_READY; @@ -3183,332 +2962,304 @@ HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_Init } /** - * @brief Initializes the TIM One Pulse Channels according to the specified - * parameters in the TIM_OnePulse_InitTypeDef. - * @param htim : TIM One Pulse handle - * @param sConfig : TIM One Pulse configuration structure - * @param OutputChannel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @param InputChannel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 selected - * @arg TIM_CHANNEL_2: TIM Channel 2 selected - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel) -{ + * @brief Initializes the TIM One Pulse Channels according to the specified + * parameters in the TIM_OnePulse_InitTypeDef. + * @param htim : TIM One Pulse handle + * @param sConfig : TIM One Pulse configuration structure + * @param OutputChannel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @param InputChannel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 selected + * @arg TIM_CHANNEL_2: TIM Channel 2 selected + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel( + TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, + uint32_t OutputChannel, uint32_t InputChannel) { TIM_OC_InitTypeDef temp1; /* Check the parameters */ assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); - if(OutputChannel != InputChannel) - { - __HAL_LOCK(htim); + if (OutputChannel != InputChannel) { + __HAL_LOCK(htim); - htim->State = HAL_TIM_STATE_BUSY; + htim->State = HAL_TIM_STATE_BUSY; - /* Extract the Ouput compare configuration from sConfig structure */ - temp1.OCMode = sConfig->OCMode; - temp1.Pulse = sConfig->Pulse; - temp1.OCPolarity = sConfig->OCPolarity; - temp1.OCNPolarity = sConfig->OCNPolarity; - temp1.OCIdleState = sConfig->OCIdleState; - temp1.OCNIdleState = sConfig->OCNIdleState; + /* Extract the Ouput compare configuration from sConfig structure */ + temp1.OCMode = sConfig->OCMode; + temp1.Pulse = sConfig->Pulse; + temp1.OCPolarity = sConfig->OCPolarity; + temp1.OCNPolarity = sConfig->OCNPolarity; + temp1.OCIdleState = sConfig->OCIdleState; + temp1.OCNIdleState = sConfig->OCNIdleState; - switch (OutputChannel) - { - case TIM_CHANNEL_1: - { + switch (OutputChannel) { + case TIM_CHANNEL_1: { assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); - TIM_OC1_SetConfig(htim->Instance, &temp1); - } - break; - case TIM_CHANNEL_2: - { + TIM_OC1_SetConfig(htim->Instance, &temp1); + } break; + case TIM_CHANNEL_2: { assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - TIM_OC2_SetConfig(htim->Instance, &temp1); + TIM_OC2_SetConfig(htim->Instance, &temp1); + } break; + default: + break; } - break; - default: - break; - } - switch (InputChannel) - { - case TIM_CHANNEL_1: - { - assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); + switch (InputChannel) { + case TIM_CHANNEL_1: { + assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); - TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, - sConfig->ICSelection, sConfig->ICFilter); + TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, + sConfig->ICSelection, sConfig->ICFilter); - /* Reset the IC1PSC Bits */ - htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; + /* Reset the IC1PSC Bits */ + htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; - /* Select the Trigger source */ + /* Select the Trigger source */ htim->Instance->SMCR &= ~TIM_SMCR_TS; - htim->Instance->SMCR |= TIM_TS_TI1FP1; + htim->Instance->SMCR |= TIM_TS_TI1FP1; - /* Select the Slave Mode */ + /* Select the Slave Mode */ htim->Instance->SMCR &= ~TIM_SMCR_SMS; - htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; - } - break; - case TIM_CHANNEL_2: - { - assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); + htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; + } break; + case TIM_CHANNEL_2: { + assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, - sConfig->ICSelection, sConfig->ICFilter); + TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, + sConfig->ICSelection, sConfig->ICFilter); - /* Reset the IC2PSC Bits */ + /* Reset the IC2PSC Bits */ htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; - /* Select the Trigger source */ + /* Select the Trigger source */ htim->Instance->SMCR &= ~TIM_SMCR_TS; - htim->Instance->SMCR |= TIM_TS_TI2FP2; + htim->Instance->SMCR |= TIM_TS_TI2FP2; - /* Select the Slave Mode */ + /* Select the Slave Mode */ htim->Instance->SMCR &= ~TIM_SMCR_SMS; - htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; + htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; + } break; + + default: + break; } - break; - default: - break; - } + htim->State = HAL_TIM_STATE_READY; - htim->State = HAL_TIM_STATE_READY; + __HAL_UNLOCK(htim); - __HAL_UNLOCK(htim); - - return HAL_OK; -} - else - { + return HAL_OK; + } else { return HAL_ERROR; } } /** - * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral - * @param htim : TIM handle - * @param BurstBaseAddress : TIM Base address from where the DMA will start the Data write - * This parameter can be one of the following values: - * @arg TIM_DMABASE_CR1 - * @arg TIM_DMABASE_CR2 - * @arg TIM_DMABASE_SMCR - * @arg TIM_DMABASE_DIER - * @arg TIM_DMABASE_SR - * @arg TIM_DMABASE_EGR - * @arg TIM_DMABASE_CCMR1 - * @arg TIM_DMABASE_CCMR2 - * @arg TIM_DMABASE_CCER - * @arg TIM_DMABASE_CNT - * @arg TIM_DMABASE_PSC - * @arg TIM_DMABASE_ARR - * @arg TIM_DMABASE_RCR - * @arg TIM_DMABASE_CCR1 - * @arg TIM_DMABASE_CCR2 - * @arg TIM_DMABASE_CCR3 - * @arg TIM_DMABASE_CCR4 - * @arg TIM_DMABASE_BDTR - * @arg TIM_DMABASE_DCR - * @param BurstRequestSrc : TIM DMA Request sources - * This parameter can be one of the following values: - * @arg TIM_DMA_UPDATE: TIM update Interrupt source - * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source - * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source - * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source - * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source - * @arg TIM_DMA_COM: TIM Commutation DMA source - * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source - * @param BurstBuffer : The Buffer address. - * @param BurstLength : DMA Burst length. This parameter can be one value - * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, - uint32_t* BurstBuffer, uint32_t BurstLength) -{ + * @brief Configure the DMA Burst to transfer Data from the memory to the TIM + * peripheral + * @param htim : TIM handle + * @param BurstBaseAddress : TIM Base address from where the DMA will start the + * Data write This parameter can be one of the following values: + * @arg TIM_DMABASE_CR1 + * @arg TIM_DMABASE_CR2 + * @arg TIM_DMABASE_SMCR + * @arg TIM_DMABASE_DIER + * @arg TIM_DMABASE_SR + * @arg TIM_DMABASE_EGR + * @arg TIM_DMABASE_CCMR1 + * @arg TIM_DMABASE_CCMR2 + * @arg TIM_DMABASE_CCER + * @arg TIM_DMABASE_CNT + * @arg TIM_DMABASE_PSC + * @arg TIM_DMABASE_ARR + * @arg TIM_DMABASE_RCR + * @arg TIM_DMABASE_CCR1 + * @arg TIM_DMABASE_CCR2 + * @arg TIM_DMABASE_CCR3 + * @arg TIM_DMABASE_CCR4 + * @arg TIM_DMABASE_BDTR + * @arg TIM_DMABASE_DCR + * @param BurstRequestSrc : TIM DMA Request sources + * This parameter can be one of the following values: + * @arg TIM_DMA_UPDATE: TIM update Interrupt source + * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source + * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source + * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source + * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source + * @arg TIM_DMA_COM: TIM Commutation DMA source + * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source + * @param BurstBuffer : The Buffer address. + * @param BurstLength : DMA Burst length. This parameter can be one value + * between: TIM_DMABURSTLENGTH_1TRANSFER and + * TIM_DMABURSTLENGTH_18TRANSFERS. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, + uint32_t BurstBaseAddress, + uint32_t BurstRequestSrc, + uint32_t *BurstBuffer, + uint32_t BurstLength) { /* Check the parameters */ assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); assert_param(IS_TIM_DMA_LENGTH(BurstLength)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if((BurstBuffer == 0U) && (BurstLength > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if ((BurstBuffer == 0U) && (BurstLength > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch(BurstRequestSrc) - { - case TIM_DMA_UPDATE: - { + switch (BurstRequestSrc) { + case TIM_DMA_UPDATE: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; + htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = + TIM_DMAPeriodElapsedCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC1: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC1: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; + htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC2: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC2: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; + htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC3: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC3: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; + htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC4: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC4: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; + htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_COM: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_COM: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; + htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = + TIMEx_DMACommutationCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_TRIGGER: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], + (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_TRIGGER: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); - } - break; + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, + (uint32_t)&htim->Instance->DMAR, + ((BurstLength) >> 8U) + 1U); + } break; default: - break; + break; } - /* configure the DMA Burst Mode */ - htim->Instance->DCR = BurstBaseAddress | BurstLength; + /* configure the DMA Burst Mode */ + htim->Instance->DCR = BurstBaseAddress | BurstLength; - /* Enable the TIM DMA Request */ - __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); + /* Enable the TIM DMA Request */ + __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); - htim->State = HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; /* Return function status */ return HAL_OK; } /** - * @brief Stops the TIM DMA Burst mode - * @param htim : TIM handle - * @param BurstRequestSrc : TIM DMA Request sources to disable - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) -{ + * @brief Stops the TIM DMA Burst mode + * @param htim : TIM handle + * @param BurstRequestSrc : TIM DMA Request sources to disable + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, + uint32_t BurstRequestSrc) { /* Check the parameters */ assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); /* Abort the DMA transfer (at least disable the DMA channel) */ - switch(BurstRequestSrc) - { - case TIM_DMA_UPDATE: - { + switch (BurstRequestSrc) { + case TIM_DMA_UPDATE: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); - } - break; - case TIM_DMA_CC1: - { + } break; + case TIM_DMA_CC1: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); - } - break; - case TIM_DMA_CC2: - { + } break; + case TIM_DMA_CC2: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); - } - break; - case TIM_DMA_CC3: - { + } break; + case TIM_DMA_CC3: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); - } - break; - case TIM_DMA_CC4: - { + } break; + case TIM_DMA_CC4: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); - } - break; - case TIM_DMA_COM: - { + } break; + case TIM_DMA_COM: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]); - } - break; - case TIM_DMA_TRIGGER: - { + } break; + case TIM_DMA_TRIGGER: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); - } - break; + } break; default: - break; + break; } /* Disable the TIM Update DMA request */ @@ -3519,155 +3270,154 @@ HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t B } /** - * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory - * @param htim : TIM handle - * @param BurstBaseAddress : TIM Base address from where the DMA will starts the Data read - * This parameter can be one of the following values: - * @arg TIM_DMABASE_CR1 - * @arg TIM_DMABASE_CR2 - * @arg TIM_DMABASE_SMCR - * @arg TIM_DMABASE_DIER - * @arg TIM_DMABASE_SR - * @arg TIM_DMABASE_EGR - * @arg TIM_DMABASE_CCMR1 - * @arg TIM_DMABASE_CCMR2 - * @arg TIM_DMABASE_CCER - * @arg TIM_DMABASE_CNT - * @arg TIM_DMABASE_PSC - * @arg TIM_DMABASE_ARR - * @arg TIM_DMABASE_RCR - * @arg TIM_DMABASE_CCR1 - * @arg TIM_DMABASE_CCR2 - * @arg TIM_DMABASE_CCR3 - * @arg TIM_DMABASE_CCR4 - * @arg TIM_DMABASE_BDTR - * @arg TIM_DMABASE_DCR - * @param BurstRequestSrc : TIM DMA Request sources - * This parameter can be one of the following values: - * @arg TIM_DMA_UPDATE: TIM update Interrupt source - * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source - * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source - * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source - * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source - * @arg TIM_DMA_COM: TIM Commutation DMA source - * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source - * @param BurstBuffer : The Buffer address. - * @param BurstLength : DMA Burst length. This parameter can be one value - * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, - uint32_t *BurstBuffer, uint32_t BurstLength) -{ + * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to + * the memory + * @param htim : TIM handle + * @param BurstBaseAddress : TIM Base address from where the DMA will starts + * the Data read This parameter can be one of the following values: + * @arg TIM_DMABASE_CR1 + * @arg TIM_DMABASE_CR2 + * @arg TIM_DMABASE_SMCR + * @arg TIM_DMABASE_DIER + * @arg TIM_DMABASE_SR + * @arg TIM_DMABASE_EGR + * @arg TIM_DMABASE_CCMR1 + * @arg TIM_DMABASE_CCMR2 + * @arg TIM_DMABASE_CCER + * @arg TIM_DMABASE_CNT + * @arg TIM_DMABASE_PSC + * @arg TIM_DMABASE_ARR + * @arg TIM_DMABASE_RCR + * @arg TIM_DMABASE_CCR1 + * @arg TIM_DMABASE_CCR2 + * @arg TIM_DMABASE_CCR3 + * @arg TIM_DMABASE_CCR4 + * @arg TIM_DMABASE_BDTR + * @arg TIM_DMABASE_DCR + * @param BurstRequestSrc : TIM DMA Request sources + * This parameter can be one of the following values: + * @arg TIM_DMA_UPDATE: TIM update Interrupt source + * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source + * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source + * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source + * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source + * @arg TIM_DMA_COM: TIM Commutation DMA source + * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source + * @param BurstBuffer : The Buffer address. + * @param BurstLength : DMA Burst length. This parameter can be one value + * between: TIM_DMABURSTLENGTH_1TRANSFER and + * TIM_DMABURSTLENGTH_18TRANSFERS. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, + uint32_t BurstBaseAddress, + uint32_t BurstRequestSrc, + uint32_t *BurstBuffer, + uint32_t BurstLength) { /* Check the parameters */ assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); assert_param(IS_TIM_DMA_LENGTH(BurstLength)); - if((htim->State == HAL_TIM_STATE_BUSY)) - { - return HAL_BUSY; - } - else if((htim->State == HAL_TIM_STATE_READY)) - { - if((BurstBuffer == 0U) && (BurstLength > 0U)) - { + if ((htim->State == HAL_TIM_STATE_BUSY)) { + return HAL_BUSY; + } else if ((htim->State == HAL_TIM_STATE_READY)) { + if ((BurstBuffer == 0U) && (BurstLength > 0U)) { return HAL_ERROR; - } - else - { + } else { htim->State = HAL_TIM_STATE_BUSY; } } - switch(BurstRequestSrc) - { - case TIM_DMA_UPDATE: - { + switch (BurstRequestSrc) { + case TIM_DMA_UPDATE: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; + htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = + TIM_DMAPeriodElapsedCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC1: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC1: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; + htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC2: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC2: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; + htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC3: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC3: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; + htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_CC4: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_CC4: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; + htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_COM: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_COM: { /* Set the DMA Period elapsed callback */ - htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; + htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = + TIMEx_DMACommutationCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; - case TIM_DMA_TRIGGER: - { + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; + case TIM_DMA_TRIGGER: { /* Set the DMA Period elapsed callback */ htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; /* Set the DMA error callback */ - htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; + htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError; /* Enable the DMA channel */ - HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); - } - break; + HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], + (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, + ((BurstLength) >> 8U) + 1U); + } break; default: - break; + break; } /* configure the DMA Burst Mode */ @@ -3683,56 +3433,41 @@ HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t B } /** - * @brief Stop the DMA burst reading - * @param htim : TIM handle - * @param BurstRequestSrc : TIM DMA Request sources to disable. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) -{ + * @brief Stop the DMA burst reading + * @param htim : TIM handle + * @param BurstRequestSrc : TIM DMA Request sources to disable. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, + uint32_t BurstRequestSrc) { /* Check the parameters */ assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); /* Abort the DMA transfer (at least disable the DMA channel) */ - switch(BurstRequestSrc) - { - case TIM_DMA_UPDATE: - { + switch (BurstRequestSrc) { + case TIM_DMA_UPDATE: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); - } - break; - case TIM_DMA_CC1: - { + } break; + case TIM_DMA_CC1: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); - } - break; - case TIM_DMA_CC2: - { + } break; + case TIM_DMA_CC2: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); - } - break; - case TIM_DMA_CC3: - { + } break; + case TIM_DMA_CC3: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); - } - break; - case TIM_DMA_CC4: - { + } break; + case TIM_DMA_CC4: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); - } - break; - case TIM_DMA_COM: - { + } break; + case TIM_DMA_COM: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]); - } - break; - case TIM_DMA_TRIGGER: - { + } break; + case TIM_DMA_TRIGGER: { HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); - } - break; + } break; default: - break; + break; } /* Disable the TIM Update DMA request */ @@ -3743,25 +3478,26 @@ HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t Bu } /** - * @brief Generate a software event - * @param htim : TIM handle - * @param EventSource : specifies the event source. - * This parameter can be one of the following values: - * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source - * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source - * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source - * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source - * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source - * @arg TIM_EVENTSOURCE_COM: Timer COM event source - * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source - * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source - * @note TIM6 and TIM7 can only generate an update event. - * @note TIM_EVENTSOURCE_COM and TIM_EVENTSOURCE_BREAK are used only with TIM1, TIM15, TIM16 and TIM17. - * @retval HAL status - */ + * @brief Generate a software event + * @param htim : TIM handle + * @param EventSource : specifies the event source. + * This parameter can be one of the following values: + * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source + * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source + * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source + * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source + * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source + * @arg TIM_EVENTSOURCE_COM: Timer COM event source + * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source + * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source + * @note TIM6 and TIM7 can only generate an update event. + * @note TIM_EVENTSOURCE_COM and TIM_EVENTSOURCE_BREAK are used only with TIM1, + * TIM15, TIM16 and TIM17. + * @retval HAL status + */ -HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) -{ +HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, + uint32_t EventSource) { /* Check the parameters */ assert_param(IS_TIM_INSTANCE(htim->Instance)); assert_param(IS_TIM_EVENT_SOURCE(EventSource)); @@ -3785,27 +3521,31 @@ HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventS } /** - * @brief Configures the OCRef clear feature - * @param htim : TIM handle - * @param sClearInputConfig : pointer to a TIM_ClearInputConfigTypeDef structure that - * contains the OCREF clear feature and parameters for the TIM peripheral. - * @param Channel : specifies the TIM Channel - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 - * @arg TIM_CHANNEL_2: TIM Channel 2 - * @arg TIM_CHANNEL_3: TIM Channel 3 - * @arg TIM_CHANNEL_4: TIM Channel 4 - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel) -{ + * @brief Configures the OCRef clear feature + * @param htim : TIM handle + * @param sClearInputConfig : pointer to a TIM_ClearInputConfigTypeDef + * structure that contains the OCREF clear feature and parameters for the TIM + * peripheral. + * @param Channel : specifies the TIM Channel + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 + * @arg TIM_CHANNEL_2: TIM Channel 2 + * @arg TIM_CHANNEL_3: TIM Channel 3 + * @arg TIM_CHANNEL_4: TIM Channel 4 + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear( + TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef *sClearInputConfig, + uint32_t Channel) { uint32_t tmpsmcr = 0U; /* Check the parameters */ assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); - assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); - assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); + assert_param( + IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); + assert_param( + IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); /* Process Locked */ @@ -3813,95 +3553,67 @@ HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInp htim->State = HAL_TIM_STATE_BUSY; - switch (sClearInputConfig->ClearInputSource) - { - case TIM_CLEARINPUTSOURCE_NONE: - { - + switch (sClearInputConfig->ClearInputSource) { + case TIM_CLEARINPUTSOURCE_NONE: { /* Clear the ETR Bits */ tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); /* Set TIMx_SMCR */ htim->Instance->SMCR = tmpsmcr; - } - break; + } break; - case TIM_CLEARINPUTSOURCE_ETR: - { - TIM_ETR_SetConfig(htim->Instance, - sClearInputConfig->ClearInputPrescaler, + case TIM_CLEARINPUTSOURCE_ETR: { + TIM_ETR_SetConfig(htim->Instance, sClearInputConfig->ClearInputPrescaler, sClearInputConfig->ClearInputPolarity, sClearInputConfig->ClearInputFilter); - } - break; + } break; default: - break; + break; } - switch (Channel) - { - case TIM_CHANNEL_1: - { - if(sClearInputConfig->ClearInputState != RESET) - { - /* Enable the Ocref clear feature for Channel 1 */ - htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; - } - else - { - /* Disable the Ocref clear feature for Channel 1 */ + switch (Channel) { + case TIM_CHANNEL_1: { + if (sClearInputConfig->ClearInputState != RESET) { + /* Enable the Ocref clear feature for Channel 1 */ + htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; + } else { + /* Disable the Ocref clear feature for Channel 1 */ htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE; - } } - break; - case TIM_CHANNEL_2: - { - assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - if(sClearInputConfig->ClearInputState != RESET) - { - /* Enable the Ocref clear feature for Channel 2 */ - htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; - } - else - { - /* Disable the Ocref clear feature for Channel 2 */ - htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; - } + } break; + case TIM_CHANNEL_2: { + assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); + if (sClearInputConfig->ClearInputState != RESET) { + /* Enable the Ocref clear feature for Channel 2 */ + htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; + } else { + /* Disable the Ocref clear feature for Channel 2 */ + htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; } - break; - case TIM_CHANNEL_3: - { - assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); - if(sClearInputConfig->ClearInputState != RESET) - { - /* Enable the Ocref clear feature for Channel 3 */ - htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; - } - else - { - /* Disable the Ocref clear feature for Channel 3 */ + } break; + case TIM_CHANNEL_3: { + assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); + if (sClearInputConfig->ClearInputState != RESET) { + /* Enable the Ocref clear feature for Channel 3 */ + htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; + } else { + /* Disable the Ocref clear feature for Channel 3 */ htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE; - } } - break; - case TIM_CHANNEL_4: - { - assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); - if(sClearInputConfig->ClearInputState != RESET) - { - /* Enable the Ocref clear feature for Channel 4 */ - htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; - } - else - { - /* Disable the Ocref clear feature for Channel 4 */ + } break; + case TIM_CHANNEL_4: { + assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); + if (sClearInputConfig->ClearInputState != RESET) { + /* Enable the Ocref clear feature for Channel 4 */ + htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; + } else { + /* Disable the Ocref clear feature for Channel 4 */ htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE; - } } - break; + } break; default: - break; + break; } htim->State = HAL_TIM_STATE_READY; @@ -3912,14 +3624,14 @@ HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInp } /** - * @brief Configures the clock source to be used - * @param htim : TIM handle - * @param sClockSourceConfig : pointer to a TIM_ClockConfigTypeDef structure that - * contains the clock source information for the TIM peripheral. - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig) -{ + * @brief Configures the clock source to be used + * @param htim : TIM handle + * @param sClockSourceConfig : pointer to a TIM_ClockConfigTypeDef structure + * that contains the clock source information for the TIM peripheral. + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_ConfigClockSource( + TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig) { uint32_t tmpsmcr = 0U; /* Process Locked */ @@ -3936,29 +3648,26 @@ HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockCo tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); htim->Instance->SMCR = tmpsmcr; - switch (sClockSourceConfig->ClockSource) - { - case TIM_CLOCKSOURCE_INTERNAL: - { + switch (sClockSourceConfig->ClockSource) { + case TIM_CLOCKSOURCE_INTERNAL: { assert_param(IS_TIM_INSTANCE(htim->Instance)); - /* Disable slave mode to clock the prescaler directly with the internal clock */ + /* Disable slave mode to clock the prescaler directly with the internal + * clock */ htim->Instance->SMCR &= ~TIM_SMCR_SMS; - } - break; + } break; - case TIM_CLOCKSOURCE_ETRMODE1: - { - /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/ + case TIM_CLOCKSOURCE_ETRMODE1: { + /* Check whether or not the timer instance supports external trigger input + * mode 1 (ETRF)*/ assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); /* Check ETR input conditioning related parameters */ assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); - + /* Configure the ETR Clock source */ - TIM_ETR_SetConfig(htim->Instance, - sClockSourceConfig->ClockPrescaler, + TIM_ETR_SetConfig(htim->Instance, sClockSourceConfig->ClockPrescaler, sClockSourceConfig->ClockPolarity, sClockSourceConfig->ClockFilter); /* Get the TIMx SMCR register value */ @@ -3969,50 +3678,46 @@ HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockCo tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); /* Write to TIMx SMCR */ htim->Instance->SMCR = tmpsmcr; - } - break; + } break; - case TIM_CLOCKSOURCE_ETRMODE2: - { - /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/ + case TIM_CLOCKSOURCE_ETRMODE2: { + /* Check whether or not the timer instance supports external trigger input + * mode 2 (ETRF)*/ assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance)); /* Check ETR input conditioning related parameters */ assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); - + /* Configure the ETR Clock source */ - TIM_ETR_SetConfig(htim->Instance, - sClockSourceConfig->ClockPrescaler, + TIM_ETR_SetConfig(htim->Instance, sClockSourceConfig->ClockPrescaler, sClockSourceConfig->ClockPolarity, sClockSourceConfig->ClockFilter); /* Enable the External clock mode2 */ htim->Instance->SMCR |= TIM_SMCR_ECE; - } - break; + } break; - case TIM_CLOCKSOURCE_TI1: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + case TIM_CLOCKSOURCE_TI1: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); /* Check TI1 input conditioning related parameters */ assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); - + TIM_TI1_ConfigInputStage(htim->Instance, sClockSourceConfig->ClockPolarity, sClockSourceConfig->ClockFilter); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); - } - break; - case TIM_CLOCKSOURCE_TI2: - { - /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/ + } break; + case TIM_CLOCKSOURCE_TI2: { + /* Check whether or not the timer instance supports external clock mode 1 + * (ETRF)*/ assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); - /* Check TI2 input conditioning related parameters */ + /* Check TI2 input conditioning related parameters */ assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); @@ -4020,11 +3725,10 @@ HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockCo sClockSourceConfig->ClockPolarity, sClockSourceConfig->ClockFilter); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); - } - break; - case TIM_CLOCKSOURCE_TI1ED: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + } break; + case TIM_CLOCKSOURCE_TI1ED: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); /* Check TI1 input conditioning related parameters */ @@ -4035,43 +3739,38 @@ HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockCo sClockSourceConfig->ClockPolarity, sClockSourceConfig->ClockFilter); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); - } - break; - case TIM_CLOCKSOURCE_ITR0: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + } break; + case TIM_CLOCKSOURCE_ITR0: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0); - } - break; - case TIM_CLOCKSOURCE_ITR1: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + } break; + case TIM_CLOCKSOURCE_ITR1: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1); - } - break; - case TIM_CLOCKSOURCE_ITR2: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + } break; + case TIM_CLOCKSOURCE_ITR2: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2); - } - break; - case TIM_CLOCKSOURCE_ITR3: - { - /* Check whether or not the timer instance supports external clock mode 1 */ + } break; + case TIM_CLOCKSOURCE_ITR3: { + /* Check whether or not the timer instance supports external clock mode 1 + */ assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3); - } - break; + } break; - default: - break; + default: + break; } htim->State = HAL_TIM_STATE_READY; @@ -4081,19 +3780,20 @@ HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockCo } /** - * @brief Selects the signal connected to the TI1 input: direct from CH1_input - * or a XOR combination between CH1_input, CH2_input & CH3_input - * @param htim : TIM handle. - * @param TI1_Selection : Indicate whether or not channel 1 is connected to the - * output of a XOR gate. - * This parameter can be one of the following values: - * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input - * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 - * pins are connected to the TI1 input (XOR combination) - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) -{ + * @brief Selects the signal connected to the TI1 input: direct from CH1_input + * or a XOR combination between CH1_input, CH2_input & CH3_input + * @param htim : TIM handle. + * @param TI1_Selection : Indicate whether or not channel 1 is connected to the + * output of a XOR gate. + * This parameter can be one of the following values: + * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 + * input + * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 + * pins are connected to the TI1 input (XOR combination) + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, + uint32_t TI1_Selection) { uint32_t tmpcr2 = 0U; /* Check the parameters */ @@ -4116,16 +3816,16 @@ HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_S } /** - * @brief Configures the TIM in Slave mode - * @param htim : TIM handle. - * @param sSlaveConfig : pointer to a TIM_SlaveConfigTypeDef structure that - * contains the selected trigger (internal trigger input, filtered - * timer input or external trigger input) and the ) and the Slave - * mode (Disable, Reset, Gated, Trigger, External clock mode 1). - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig) -{ + * @brief Configures the TIM in Slave mode + * @param htim : TIM handle. + * @param sSlaveConfig : pointer to a TIM_SlaveConfigTypeDef structure that + * contains the selected trigger (internal trigger input, filtered + * timer input or external trigger input) and the ) and the Slave + * mode (Disable, Reset, Gated, Trigger, External clock mode 1). + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization( + TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig) { /* Check the parameters */ assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); @@ -4148,21 +3848,20 @@ HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TI __HAL_UNLOCK(htim); return HAL_OK; - } +} /** - * @brief Configures the TIM in Slave mode in interrupt mode - * @param htim: TIM handle. - * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that - * contains the selected trigger (internal trigger input, filtered - * timer input or external trigger input) and the ) and the Slave - * mode (Disable, Reset, Gated, Trigger, External clock mode 1). - * @retval HAL status - */ -HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, - TIM_SlaveConfigTypeDef * sSlaveConfig) - { - /* Check the parameters */ + * @brief Configures the TIM in Slave mode in interrupt mode + * @param htim: TIM handle. + * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that + * contains the selected trigger (internal trigger input, filtered + * timer input or external trigger input) and the ) and the Slave + * mode (Disable, Reset, Gated, Trigger, External clock mode 1). + * @retval HAL status + */ +HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT( + TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig) { + /* Check the parameters */ assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); @@ -4187,69 +3886,63 @@ HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, } /** - * @brief Read the captured value from Capture Compare unit - * @param htim : TIM handle. - * @param Channel : TIM Channels to be enabled - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1 : TIM Channel 1 selected - * @arg TIM_CHANNEL_2 : TIM Channel 2 selected - * @arg TIM_CHANNEL_3 : TIM Channel 3 selected - * @arg TIM_CHANNEL_4 : TIM Channel 4 selected - * @retval Captured value - */ -uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) -{ + * @brief Read the captured value from Capture Compare unit + * @param htim : TIM handle. + * @param Channel : TIM Channels to be enabled + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1 : TIM Channel 1 selected + * @arg TIM_CHANNEL_2 : TIM Channel 2 selected + * @arg TIM_CHANNEL_3 : TIM Channel 3 selected + * @arg TIM_CHANNEL_4 : TIM Channel 4 selected + * @retval Captured value + */ +uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) { uint32_t tmpreg = 0U; __HAL_LOCK(htim); - switch (Channel) - { - case TIM_CHANNEL_1: - { + switch (Channel) { + case TIM_CHANNEL_1: { /* Check the parameters */ assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); /* Return the capture 1 value */ - tmpreg = htim->Instance->CCR1; + tmpreg = htim->Instance->CCR1; break; } - case TIM_CHANNEL_2: - { + case TIM_CHANNEL_2: { /* Check the parameters */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); /* Return the capture 2 value */ - tmpreg = htim->Instance->CCR2; + tmpreg = htim->Instance->CCR2; break; } - case TIM_CHANNEL_3: - { + case TIM_CHANNEL_3: { /* Check the parameters */ assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); /* Return the capture 3 value */ - tmpreg = htim->Instance->CCR3; + tmpreg = htim->Instance->CCR3; break; } - case TIM_CHANNEL_4: - { + case TIM_CHANNEL_4: { /* Check the parameters */ assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); /* Return the capture 4 value */ - tmpreg = htim->Instance->CCR4; + tmpreg = htim->Instance->CCR4; break; } - default: - break; + default: + break; } __HAL_UNLOCK(htim); @@ -4257,13 +3950,13 @@ uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) } /** - * @} - */ + * @} + */ /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions - * @brief TIM Callbacks functions + * @brief TIM Callbacks functions * -@verbatim +@verbatim ============================================================================== ##### TIM Callbacks functions ##### ============================================================================== @@ -4280,67 +3973,65 @@ uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) */ /** - * @brief Period elapsed callback in non blocking mode - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) -{ + * @brief Period elapsed callback in non blocking mode + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, - the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file - */ - -} -/** - * @brief Output Compare callback in non blocking mode - * @param htim : TIM OC handle - * @retval None - */ -__weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) -{ - /* Prevent unused argument(s) compilation warning */ - UNUSED(htim); - /* NOTE : This function Should not be modified, when the callback is needed, - the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file + the __HAL_TIM_PeriodElapsedCallback could be implemented in the user + file */ } /** - * @brief Input Capture callback in non blocking mode - * @param htim : TIM IC handle - * @retval None - */ -__weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) -{ + * @brief Output Compare callback in non blocking mode + * @param htim : TIM OC handle + * @retval None + */ +__weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, - the __HAL_TIM_IC_CaptureCallback could be implemented in the user file + the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the + user file + */ +} +/** + * @brief Input Capture callback in non blocking mode + * @param htim : TIM IC handle + * @retval None + */ +__weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) { + /* Prevent unused argument(s) compilation warning */ + UNUSED(htim); + /* NOTE : This function Should not be modified, when the callback is needed, + the __HAL_TIM_IC_CaptureCallback could be implemented in the user + file */ } /** - * @brief PWM Pulse finished callback in non blocking mode - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) -{ + * @brief PWM Pulse finished callback in non blocking mode + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, - the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file + the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the + user file */ } /** - * @brief Hall Trigger detection callback in non blocking mode - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) -{ + * @brief Hall Trigger detection callback in non blocking mode + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -4349,12 +4040,11 @@ __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) } /** - * @brief Timer error callback in non blocking mode - * @param htim : TIM handle - * @retval None - */ -__weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) -{ + * @brief Timer error callback in non blocking mode + * @param htim : TIM handle + * @retval None + */ +__weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) { /* Prevent unused argument(s) compilation warning */ UNUSED(htim); /* NOTE : This function Should not be modified, when the callback is needed, @@ -4363,18 +4053,18 @@ __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) } /** - * @} - */ + * @} + */ -/** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions - * @brief Peripheral State functions +/** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions + * @brief Peripheral State functions * -@verbatim +@verbatim ============================================================================== ##### Peripheral State functions ##### ============================================================================== [..] - This subsection permit to get in run-time the status of the peripheral + This subsection permit to get in run-time the status of the peripheral and the data flow. @endverbatim @@ -4382,116 +4072,103 @@ __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) */ /** - * @brief Return the TIM Base state - * @param htim : TIM Base handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM Base state + * @param htim : TIM Base handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @brief Return the TIM OC state - * @param htim : TIM Ouput Compare handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM OC state + * @param htim : TIM Ouput Compare handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @brief Return the TIM PWM state - * @param htim : TIM handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM PWM state + * @param htim : TIM handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @brief Return the TIM Input Capture state - * @param htim : TIM IC handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM Input Capture state + * @param htim : TIM IC handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @brief Return the TIM One Pulse Mode state - * @param htim : TIM OPM handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM One Pulse Mode state + * @param htim : TIM OPM handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @brief Return the TIM Encoder Mode state - * @param htim : TIM Encoder handle - * @retval HAL state - */ -HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) -{ + * @brief Return the TIM Encoder Mode state + * @param htim : TIM Encoder handle + * @retval HAL state + */ +HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) { return htim->State; } /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /** @addtogroup TIM_Private_Functions - * @{ - */ + * @{ + */ /** - * @brief TIM DMA error callback - * @param hdma : pointer to DMA handle. - * @retval None - */ -void TIM_DMAError(DMA_HandleTypeDef *hdma) -{ - TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; + * @brief TIM DMA error callback + * @param hdma : pointer to DMA handle. + * @retval None + */ +void TIM_DMAError(DMA_HandleTypeDef *hdma) { + TIM_HandleTypeDef *htim = + (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; HAL_TIM_ErrorCallback(htim); } /** - * @brief TIM DMA Delay Pulse complete callback. - * @param hdma : pointer to DMA handle. - * @retval None - */ -void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) -{ - TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; + * @brief TIM DMA Delay Pulse complete callback. + * @param hdma : pointer to DMA handle. + * @retval None + */ +void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) { + TIM_HandleTypeDef *htim = + (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; - if (hdma == htim->hdma[TIM_DMA_ID_CC1]) - { + if (hdma == htim->hdma[TIM_DMA_ID_CC1]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; } @@ -4500,30 +4177,23 @@ void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; } /** - * @brief TIM DMA Capture complete callback. - * @param hdma : pointer to DMA handle. - * @retval None - */ -void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) -{ - TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; + * @brief TIM DMA Capture complete callback. + * @param hdma : pointer to DMA handle. + * @retval None + */ +void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) { + TIM_HandleTypeDef *htim = + (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; - if (hdma == htim->hdma[TIM_DMA_ID_CC1]) - { + if (hdma == htim->hdma[TIM_DMA_ID_CC1]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; - } - else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) - { + } else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) { htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; } @@ -4533,54 +4203,51 @@ void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) } /** - * @brief TIM DMA Period Elapse complete callback. - * @param hdma : pointer to DMA handle. - * @retval None - */ -static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) -{ - TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; + * @brief TIM DMA Period Elapse complete callback. + * @param hdma : pointer to DMA handle. + * @retval None + */ +static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) { + TIM_HandleTypeDef *htim = + (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; HAL_TIM_PeriodElapsedCallback(htim); } /** - * @brief TIM DMA Trigger callback. - * @param hdma : pointer to DMA handle. - * @retval None - */ -static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) -{ - TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; + * @brief TIM DMA Trigger callback. + * @param hdma : pointer to DMA handle. + * @retval None + */ +static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) { + TIM_HandleTypeDef *htim = + (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; - htim->State= HAL_TIM_STATE_READY; + htim->State = HAL_TIM_STATE_READY; HAL_TIM_TriggerCallback(htim); } /** - * @brief Time Base configuration - * @param TIMx : TIM periheral - * @param Structure : TIM Base configuration structure - * @retval None - */ -void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) -{ + * @brief Time Base configuration + * @param TIMx : TIM periheral + * @param Structure : TIM Base configuration structure + * @retval None + */ +void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) { uint32_t tmpcr1 = 0U; tmpcr1 = TIMx->CR1; /* Set TIM Time Base Unit parameters ---------------------------------------*/ - if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) - { + if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) { /* Select the Counter Mode */ tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); tmpcr1 |= Structure->CounterMode; } - if(IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) - { + if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) { /* Set the clock division */ tmpcr1 &= ~TIM_CR1_CKD; tmpcr1 |= (uint32_t)Structure->ClockDivision; @@ -4593,41 +4260,40 @@ void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) TIMx->CR1 = tmpcr1; /* Set the Autoreload value */ - TIMx->ARR = (uint32_t)Structure->Period ; + TIMx->ARR = (uint32_t)Structure->Period; /* Set the Prescaler value */ TIMx->PSC = (uint32_t)Structure->Prescaler; - if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx)) - { + if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx)) { /* Set the Repetition Counter value */ TIMx->RCR = Structure->RepetitionCounter; } - /* Generate an update event to reload the Prescaler + /* Generate an update event to reload the Prescaler and the repetition counter(only for TIM1 and TIM8) value immediatly */ TIMx->EGR = TIM_EGR_UG; } /** - * @brief Time Ouput Compare 1 configuration - * @param TIMx to select the TIM peripheral - * @param OC_Config : The ouput configuration structure - * @retval None - */ -static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) -{ + * @brief Time Ouput Compare 1 configuration + * @param TIMx to select the TIM peripheral + * @param OC_Config : The ouput configuration structure + * @retval None + */ +static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, + TIM_OC_InitTypeDef *OC_Config) { uint32_t tmpccmrx = 0U; uint32_t tmpccer = 0U; uint32_t tmpcr2 = 0U; - /* Disable the Channel 1: Reset the CC1E Bit */ + /* Disable the Channel 1: Reset the CC1E Bit */ TIMx->CCER &= ~TIM_CCER_CC1E; /* Get the TIMx CCER register value */ tmpccer = TIMx->CCER; /* Get the TIMx CR2 register value */ - tmpcr2 = TIMx->CR2; + tmpcr2 = TIMx->CR2; /* Get the TIMx CCMR1 register value */ tmpccmrx = TIMx->CCMR1; @@ -4643,8 +4309,7 @@ static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Set the Output Compare Polarity */ tmpccer |= OC_Config->OCPolarity; - if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1)) - { + if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1)) { /* Check parameters */ assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); @@ -4656,8 +4321,7 @@ static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) tmpccer &= ~TIM_CCER_CC1NE; } - if(IS_TIM_BREAK_INSTANCE(TIMx)) - { + if (IS_TIM_BREAK_INSTANCE(TIMx)) { /* Check parameters */ assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); @@ -4684,13 +4348,12 @@ static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) } /** - * @brief Time Ouput Compare 2 configuration - * @param TIMx to select the TIM peripheral - * @param OC_Config : The ouput configuration structure - * @retval None - */ -void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) -{ + * @brief Time Ouput Compare 2 configuration + * @param TIMx to select the TIM peripheral + * @param OC_Config : The ouput configuration structure + * @retval None + */ +void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) { uint32_t tmpccmrx = 0U; uint32_t tmpccer = 0U; uint32_t tmpcr2 = 0U; @@ -4701,7 +4364,7 @@ void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Get the TIMx CCER register value */ tmpccer = TIMx->CCER; /* Get the TIMx CR2 register value */ - tmpcr2 = TIMx->CR2; + tmpcr2 = TIMx->CR2; /* Get the TIMx CCMR1 register value */ tmpccmrx = TIMx->CCMR1; @@ -4718,8 +4381,7 @@ void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Set the Output Compare Polarity */ tmpccer |= (OC_Config->OCPolarity << 4U); - if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2)) - { + if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2)) { assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); /* Reset the Output N Polarity level */ @@ -4728,11 +4390,9 @@ void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) tmpccer |= (OC_Config->OCNPolarity << 4U); /* Reset the Output N State */ tmpccer &= ~TIM_CCER_CC2NE; - } - if(IS_TIM_BREAK_INSTANCE(TIMx)) - { + if (IS_TIM_BREAK_INSTANCE(TIMx)) { /* Check parameters */ assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); @@ -4760,13 +4420,13 @@ void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) } /** - * @brief Time Ouput Compare 3 configuration - * @param TIMx to select the TIM peripheral - * @param OC_Config : The ouput configuration structure - * @retval None - */ -static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) -{ + * @brief Time Ouput Compare 3 configuration + * @param TIMx to select the TIM peripheral + * @param OC_Config : The ouput configuration structure + * @retval None + */ +static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, + TIM_OC_InitTypeDef *OC_Config) { uint32_t tmpccmrx = 0U; uint32_t tmpccer = 0U; uint32_t tmpcr2 = 0U; @@ -4777,7 +4437,7 @@ static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Get the TIMx CCER register value */ tmpccer = TIMx->CCER; /* Get the TIMx CR2 register value */ - tmpcr2 = TIMx->CR2; + tmpcr2 = TIMx->CR2; /* Get the TIMx CCMR2 register value */ tmpccmrx = TIMx->CCMR2; @@ -4793,8 +4453,7 @@ static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Set the Output Compare Polarity */ tmpccer |= (OC_Config->OCPolarity << 8U); - if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3)) - { + if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3)) { assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); /* Reset the Output N Polarity level */ @@ -4805,8 +4464,7 @@ static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) tmpccer &= ~TIM_CCER_CC3NE; } - if(IS_TIM_BREAK_INSTANCE(TIMx)) - { + if (IS_TIM_BREAK_INSTANCE(TIMx)) { /* Check parameters */ assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); @@ -4834,13 +4492,13 @@ static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) } /** - * @brief Time Ouput Compare 4 configuration - * @param TIMx to select the TIM peripheral - * @param OC_Config : The ouput configuration structure - * @retval None - */ -static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) -{ + * @brief Time Ouput Compare 4 configuration + * @param TIMx to select the TIM peripheral + * @param OC_Config : The ouput configuration structure + * @retval None + */ +static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, + TIM_OC_InitTypeDef *OC_Config) { uint32_t tmpccmrx = 0U; uint32_t tmpccer = 0U; uint32_t tmpcr2 = 0U; @@ -4851,7 +4509,7 @@ static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Get the TIMx CCER register value */ tmpccer = TIMx->CCER; /* Get the TIMx CR2 register value */ - tmpcr2 = TIMx->CR2; + tmpcr2 = TIMx->CR2; /* Get the TIMx CCMR2 register value */ tmpccmrx = TIMx->CCMR2; @@ -4868,11 +4526,10 @@ static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) /* Set the Output Compare Polarity */ tmpccer |= (OC_Config->OCPolarity << 12U); - if(IS_TIM_BREAK_INSTANCE(TIMx)) - { + if (IS_TIM_BREAK_INSTANCE(TIMx)) { assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); - /* Reset the Output Compare IDLE State */ + /* Reset the Output Compare IDLE State */ tmpcr2 &= ~TIM_CR2_OIS4; /* Set the Output Idle state */ tmpcr2 |= (OC_Config->OCIdleState << 6); @@ -4891,17 +4548,15 @@ static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) TIMx->CCER = tmpccer; } - /** - * @brief Time Slave configuration - * @param htim: pointer to a TIM_HandleTypeDef structure that contains - * the configuration information for TIM module. - * @param sSlaveConfig: The slave configuration structure - * @retval None - */ + * @brief Time Slave configuration + * @param htim: pointer to a TIM_HandleTypeDef structure that contains + * the configuration information for TIM module. + * @param sSlaveConfig: The slave configuration structure + * @retval None + */ static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, - TIM_SlaveConfigTypeDef * sSlaveConfig) -{ + TIM_SlaveConfigTypeDef *sSlaveConfig) { uint32_t tmpsmcr = 0U; uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; @@ -4923,25 +4578,20 @@ static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, htim->Instance->SMCR = tmpsmcr; /* Configure the trigger prescaler, filter, and polarity */ - switch (sSlaveConfig->InputTrigger) - { - case TIM_TS_ETRF: - { + switch (sSlaveConfig->InputTrigger) { + case TIM_TS_ETRF: { /* Check the parameters */ assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); /* Configure the ETR Trigger source */ - TIM_ETR_SetConfig(htim->Instance, - sSlaveConfig->TriggerPrescaler, + TIM_ETR_SetConfig(htim->Instance, sSlaveConfig->TriggerPrescaler, sSlaveConfig->TriggerPolarity, sSlaveConfig->TriggerFilter); - } - break; + } break; - case TIM_TS_TI1F_ED: - { + case TIM_TS_TI1F_ED: { /* Check the parameters */ assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); @@ -4959,92 +4609,79 @@ static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, htim->Instance->CCMR1 = tmpccmr1; htim->Instance->CCER = tmpccer; - } - break; + } break; - case TIM_TS_TI1FP1: - { + case TIM_TS_TI1FP1: { /* Check the parameters */ assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); /* Configure TI1 Filter and Polarity */ - TIM_TI1_ConfigInputStage(htim->Instance, - sSlaveConfig->TriggerPolarity, + TIM_TI1_ConfigInputStage(htim->Instance, sSlaveConfig->TriggerPolarity, sSlaveConfig->TriggerFilter); - } - break; + } break; - case TIM_TS_TI2FP2: - { + case TIM_TS_TI2FP2: { /* Check the parameters */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); /* Configure TI2 Filter and Polarity */ - TIM_TI2_ConfigInputStage(htim->Instance, - sSlaveConfig->TriggerPolarity, - sSlaveConfig->TriggerFilter); - } - break; + TIM_TI2_ConfigInputStage(htim->Instance, sSlaveConfig->TriggerPolarity, + sSlaveConfig->TriggerFilter); + } break; - case TIM_TS_ITR0: - { + case TIM_TS_ITR0: { /* Check the parameter */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - } - break; + } break; - case TIM_TS_ITR1: - { + case TIM_TS_ITR1: { /* Check the parameter */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - } - break; + } break; - case TIM_TS_ITR2: - { + case TIM_TS_ITR2: { /* Check the parameter */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - } - break; + } break; - case TIM_TS_ITR3: - { + case TIM_TS_ITR3: { /* Check the parameter */ assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); - } - break; + } break; - default: - break; + default: + break; } } /** - * @brief Configure the TI1 as Input. - * @param TIMx to select the TIM peripheral. - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICSelection : specifies the input to be used. - * This parameter can be one of the following values: - * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. - * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. - * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @retval None - * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 - * (on channel2 path) is used as the input signal. Therefore CCMR1 must be - * protected against un-initialized filter and polarity values. - */ -void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter) -{ + * @brief Configure the TI1 as Input. + * @param TIMx to select the TIM peripheral. + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICSelection : specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be + * connected to IC1. + * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be + * connected to IC2. + * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be + * connected to TRC. + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @retval None + * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 + * (on channel2 path) is used as the input signal. Therefore CCMR1 must be + * protected against un-initialized filter and polarity values. + */ +void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter) { uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; @@ -5054,13 +4691,10 @@ void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ tmpccer = TIMx->CCER; /* Select the Input */ - if(IS_TIM_CC2_INSTANCE(TIMx) != RESET) - { + if (IS_TIM_CC2_INSTANCE(TIMx) != RESET) { tmpccmr1 &= ~TIM_CCMR1_CC1S; tmpccmr1 |= TIM_ICSelection; - } - else - { + } else { tmpccmr1 |= TIM_CCMR1_CC1S_0; } @@ -5078,18 +4712,18 @@ void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ } /** - * @brief Configure the Polarity and Filter for TI1. - * @param TIMx to select the TIM peripheral. - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @retval None - */ -static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) -{ + * @brief Configure the Polarity and Filter for TI1. + * @param TIMx to select the TIM peripheral. + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @retval None + */ +static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICFilter) { uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; @@ -5112,27 +4746,29 @@ static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, } /** - * @brief Configure the TI2 as Input. - * @param TIMx to select the TIM peripheral - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICSelection : specifies the input to be used. - * This parameter can be one of the following values: - * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2. - * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1. - * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC. - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @retval None - * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 - * (on channel1 path) is used as the input signal. Therefore CCMR1 must be - * protected against un-initialized filter and polarity values. - */ -static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter) -{ + * @brief Configure the TI2 as Input. + * @param TIMx to select the TIM peripheral + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICSelection : specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be + * connected to IC2. + * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be + * connected to IC1. + * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be + * connected to TRC. + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @retval None + * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 + * (on channel1 path) is used as the input signal. Therefore CCMR1 must be + * protected against un-initialized filter and polarity values. + */ +static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter) { uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; @@ -5154,23 +4790,23 @@ static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32 tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP)); /* Write to TIMx CCMR1 and CCER registers */ - TIMx->CCMR1 = tmpccmr1 ; + TIMx->CCMR1 = tmpccmr1; TIMx->CCER = tmpccer; } /** - * @brief Configure the Polarity and Filter for TI2. - * @param TIMx to select the TIM peripheral. - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @retval None - */ -static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) -{ + * @brief Configure the Polarity and Filter for TI2. + * @param TIMx to select the TIM peripheral. + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @retval None + */ +static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICFilter) { uint32_t tmpccmr1 = 0U; uint32_t tmpccer = 0U; @@ -5188,32 +4824,34 @@ static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, tmpccer |= (TIM_ICPolarity << 4U); /* Write to TIMx CCMR1 and CCER registers */ - TIMx->CCMR1 = tmpccmr1 ; + TIMx->CCMR1 = tmpccmr1; TIMx->CCER = tmpccer; } /** - * @brief Configure the TI3 as Input. - * @param TIMx to select the TIM peripheral - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICSelection : specifies the input to be used. - * This parameter can be one of the following values: - * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3. - * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4. - * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC. - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @retval None - * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 - * (on channel1 path) is used as the input signal. Therefore CCMR2 must be - * protected against un-initialized filter and polarity values. - */ -static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter) -{ + * @brief Configure the TI3 as Input. + * @param TIMx to select the TIM peripheral + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICSelection : specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be + * connected to IC3. + * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be + * connected to IC4. + * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be + * connected to TRC. + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @retval None + * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 + * (on channel1 path) is used as the input signal. Therefore CCMR2 must be + * protected against un-initialized filter and polarity values. + */ +static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter) { uint32_t tmpccmr2 = 0U; uint32_t tmpccer = 0U; @@ -5240,27 +4878,29 @@ static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32 } /** - * @brief Configure the TI4 as Input. - * @param TIMx to select the TIM peripheral - * @param TIM_ICPolarity : The Input Polarity. - * This parameter can be one of the following values: - * @arg TIM_ICPOLARITY_RISING - * @arg TIM_ICPOLARITY_FALLING - * @param TIM_ICSelection : specifies the input to be used. - * This parameter can be one of the following values: - * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4. - * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3. - * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC. - * @param TIM_ICFilter : Specifies the Input Capture Filter. - * This parameter must be a value between 0x00 and 0x0F. - * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 - * (on channel1 path) is used as the input signal. Therefore CCMR2 must be - * protected against un-initialized filter and polarity values. - * @retval None - */ -static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, - uint32_t TIM_ICFilter) -{ + * @brief Configure the TI4 as Input. + * @param TIMx to select the TIM peripheral + * @param TIM_ICPolarity : The Input Polarity. + * This parameter can be one of the following values: + * @arg TIM_ICPOLARITY_RISING + * @arg TIM_ICPOLARITY_FALLING + * @param TIM_ICSelection : specifies the input to be used. + * This parameter can be one of the following values: + * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be + * connected to IC4. + * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be + * connected to IC3. + * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be + * connected to TRC. + * @param TIM_ICFilter : Specifies the Input Capture Filter. + * This parameter must be a value between 0x00 and 0x0F. + * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 + * (on channel1 path) is used as the input signal. Therefore CCMR2 must be + * protected against un-initialized filter and polarity values. + * @retval None + */ +static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, + uint32_t TIM_ICSelection, uint32_t TIM_ICFilter) { uint32_t tmpccmr2 = 0U; uint32_t tmpccer = 0U; @@ -5283,57 +4923,57 @@ static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32 /* Write to TIMx CCMR2 and CCER registers */ TIMx->CCMR2 = tmpccmr2; - TIMx->CCER = tmpccer ; + TIMx->CCER = tmpccer; } /** - * @brief Selects the Input Trigger source - * @param TIMx to select the TIM peripheral - * @param InputTriggerSource : The Input Trigger source. - * This parameter can be one of the following values: - * @arg TIM_TS_ITR0 : Internal Trigger 0 - * @arg TIM_TS_ITR1 : Internal Trigger 1 - * @arg TIM_TS_ITR2 : Internal Trigger 2 - * @arg TIM_TS_ITR3 : Internal Trigger 3 - * @arg TIM_TS_TI1F_ED : TI1 Edge Detector - * @arg TIM_TS_TI1FP1 : Filtered Timer Input 1 - * @arg TIM_TS_TI2FP2 : Filtered Timer Input 2 - * @arg TIM_TS_ETRF : External Trigger input - * @retval None - */ -static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource) -{ + * @brief Selects the Input Trigger source + * @param TIMx to select the TIM peripheral + * @param InputTriggerSource : The Input Trigger source. + * This parameter can be one of the following values: + * @arg TIM_TS_ITR0 : Internal Trigger 0 + * @arg TIM_TS_ITR1 : Internal Trigger 1 + * @arg TIM_TS_ITR2 : Internal Trigger 2 + * @arg TIM_TS_ITR3 : Internal Trigger 3 + * @arg TIM_TS_TI1F_ED : TI1 Edge Detector + * @arg TIM_TS_TI1FP1 : Filtered Timer Input 1 + * @arg TIM_TS_TI2FP2 : Filtered Timer Input 2 + * @arg TIM_TS_ETRF : External Trigger input + * @retval None + */ +static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource) { uint32_t tmpsmcr = 0U; - /* Get the TIMx SMCR register value */ - tmpsmcr = TIMx->SMCR; - /* Reset the TS Bits */ - tmpsmcr &= ~TIM_SMCR_TS; - /* Set the Input Trigger source and the slave mode*/ - tmpsmcr |= InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1; - /* Write to TIMx SMCR */ - TIMx->SMCR = tmpsmcr; + /* Get the TIMx SMCR register value */ + tmpsmcr = TIMx->SMCR; + /* Reset the TS Bits */ + tmpsmcr &= ~TIM_SMCR_TS; + /* Set the Input Trigger source and the slave mode*/ + tmpsmcr |= InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1; + /* Write to TIMx SMCR */ + TIMx->SMCR = tmpsmcr; } /** - * @brief Configures the TIMx External Trigger (ETR). - * @param TIMx to select the TIM peripheral - * @param TIM_ExtTRGPrescaler : The external Trigger Prescaler. - * This parameter can be one of the following values: - * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. - * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. - * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. - * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. - * @param TIM_ExtTRGPolarity : The external Trigger Polarity. - * This parameter can be one of the following values: - * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. - * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active. - * @param ExtTRGFilter : External Trigger Filter. - * This parameter must be a value between 0x00 and 0x0F - * @retval None - */ -static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, - uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) -{ + * @brief Configures the TIMx External Trigger (ETR). + * @param TIMx to select the TIM peripheral + * @param TIM_ExtTRGPrescaler : The external Trigger Prescaler. + * This parameter can be one of the following values: + * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. + * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. + * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. + * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. + * @param TIM_ExtTRGPolarity : The external Trigger Polarity. + * This parameter can be one of the following values: + * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. + * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge + * active. + * @param ExtTRGFilter : External Trigger Filter. + * This parameter must be a value between 0x00 and 0x0F + * @retval None + */ +static void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, + uint32_t TIM_ExtTRGPolarity, + uint32_t ExtTRGFilter) { uint32_t tmpsmcr = 0U; tmpsmcr = TIMx->SMCR; @@ -5342,27 +4982,28 @@ static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); /* Set the Prescaler, the Filter value and the Polarity */ - tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U))); + tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | + (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U))); /* Write to TIMx SMCR */ TIMx->SMCR = tmpsmcr; } /** - * @brief Enables or disables the TIM Capture Compare Channel x. - * @param TIMx to select the TIM peripheral - * @param Channel : specifies the TIM Channel - * This parameter can be one of the following values: - * @arg TIM_CHANNEL_1: TIM Channel 1 - * @arg TIM_CHANNEL_2: TIM Channel 2 - * @arg TIM_CHANNEL_3: TIM Channel 3 - * @arg TIM_CHANNEL_4: TIM Channel 4 - * @param ChannelState : specifies the TIM Channel CCxE bit new state. - * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. - * @retval None - */ -void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState) -{ + * @brief Enables or disables the TIM Capture Compare Channel x. + * @param TIMx to select the TIM peripheral + * @param Channel : specifies the TIM Channel + * This parameter can be one of the following values: + * @arg TIM_CHANNEL_1: TIM Channel 1 + * @arg TIM_CHANNEL_2: TIM Channel 2 + * @arg TIM_CHANNEL_3: TIM Channel 3 + * @arg TIM_CHANNEL_4: TIM Channel 4 + * @param ChannelState : specifies the TIM Channel CCxE bit new state. + * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. + * @retval None + */ +void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, + uint32_t ChannelState) { uint32_t tmp = 0U; /* Check the parameters */ @@ -5375,19 +5016,19 @@ void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelStat TIMx->CCER &= ~tmp; /* Set or reset the CCxE Bit */ - TIMx->CCER |= (uint32_t)(ChannelState << Channel); + TIMx->CCER |= (uint32_t)(ChannelState << Channel); } /** - * @} - */ + * @} + */ #endif /* HAL_TIM_MODULE_ENABLED */ /** - * @} - */ + * @} + */ /** - * @} - */ + * @} + */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/workspace/TS100/Makefile b/workspace/TS100/Makefile index f0be4f53..1a9030a5 100644 --- a/workspace/TS100/Makefile +++ b/workspace/TS100/Makefile @@ -1,5 +1,8 @@ -OUTPUT_EXE=TS100_$(lang) +ifndef model +model:=TS100 +endif +OUTPUT_EXE=$(model)_$(lang) ifndef lang lang:= EN endif @@ -36,7 +39,7 @@ OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color # global defines --------------------------------------------------------------- -GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG +GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) # Enable debug code generation DEBUG=-g diff --git a/workspace/TS100/inc/FRToSI2C.hpp b/workspace/TS100/inc/FRToSI2C.hpp index a3544081..b62d1ac3 100644 --- a/workspace/TS100/inc/FRToSI2C.hpp +++ b/workspace/TS100/inc/FRToSI2C.hpp @@ -11,29 +11,30 @@ #include "cmsis_os.h" class FRToSI2C { - public: +public: - FRToSI2C(I2C_HandleTypeDef *i2chandle) : i2c(i2chandle), - I2CSemaphore(nullptr) { - } + static void init(I2C_HandleTypeDef *i2chandle) {i2c=i2chandle; + I2CSemaphore=nullptr;} - void FRToSInit() { + static void FRToSInit() { I2CSemaphore = xSemaphoreCreateBinary(); xSemaphoreGive(I2CSemaphore); } - void CpltCallback(); //Normal Tx Callback + static void CpltCallback(); //Normal Tx Callback - void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, - uint8_t *pData, uint16_t Size); - void Mem_Write(uint16_t DevAddress, uint16_t MemAddress, - uint16_t MemAddSize, uint8_t *pData, uint16_t Size); + static void Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, + uint8_t *pData, uint16_t Size); + static void Mem_Write(uint16_t DevAddress, uint16_t MemAddress, + uint16_t MemAddSize, uint8_t *pData, uint16_t Size); - void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size); + static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size); + static void I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data); + static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg); - private: - I2C_HandleTypeDef *i2c; - SemaphoreHandle_t I2CSemaphore; +private: + static I2C_HandleTypeDef *i2c; + static SemaphoreHandle_t I2CSemaphore; }; #endif /* FRTOSI2C_HPP_ */ diff --git a/workspace/TS100/inc/FreeRTOSConfig.h b/workspace/TS100/inc/FreeRTOSConfig.h index 9d2b6c33..4c787b06 100644 --- a/workspace/TS100/inc/FreeRTOSConfig.h +++ b/workspace/TS100/inc/FreeRTOSConfig.h @@ -102,12 +102,12 @@ #define configMAX_PRIORITIES ( 4 ) #define configMINIMAL_STACK_SIZE ((uint16_t)256) #define configTOTAL_HEAP_SIZE ((size_t)10240) /*Currently use about 9000*/ -#define configMAX_TASK_NAME_LEN ( 48 ) +#define configMAX_TASK_NAME_LEN ( 24 ) #define configUSE_16_BIT_TICKS 0 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1 -#define configCHECK_FOR_STACK_OVERFLOW 2 +#define configCHECK_FOR_STACK_OVERFLOW 0 /*Bump this to 2 during development and bug hunting*/ /* Co-routine definitions. */ @@ -117,10 +117,10 @@ /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ #define INCLUDE_vTaskPrioritySet 1 -#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_uxTaskPriorityGet 0 #define INCLUDE_vTaskDelete 0 #define INCLUDE_vTaskCleanUpResources 0 -#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskSuspend 0 #define INCLUDE_vTaskDelayUntil 0 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 diff --git a/workspace/TS100/inc/LIS2DH12.hpp b/workspace/TS100/inc/LIS2DH12.hpp index 2721e7c4..b292db32 100644 --- a/workspace/TS100/inc/LIS2DH12.hpp +++ b/workspace/TS100/inc/LIS2DH12.hpp @@ -14,15 +14,29 @@ class LIS2DH12 { public: - LIS2DH12(FRToSI2C* i2cHandle) : i2c(i2cHandle) {} - void initalize(); - Orientation getOrientation() { return static_cast((I2C_RegisterRead(LIS_INT2_SRC) >> 2) - 1); } - void getAxisReadings(int16_t *x, int16_t *y, int16_t *z); + static void initalize(); + //1 = rh, 2,=lh, 8=flat + static Orientation getOrientation() { +#ifdef MODEL_TS80 + uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, + LIS_INT2_SRC) >> 2); + if (val == 8) + val = 3; + else if (val==1) + val=0; + else if(val==2) + val=1; + else + val=3; + return static_cast(val); +#endif +#ifdef MODEL_TS100 + return static_cast((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,LIS_INT2_SRC) >> 2) - 1); +#endif + } + static void getAxisReadings(int16_t *x, int16_t *y, int16_t *z); private: - void I2C_RegisterWrite(uint8_t reg, uint8_t data); - uint8_t I2C_RegisterRead(uint8_t reg); - FRToSI2C* i2c; }; #endif /* LIS2DH12_HPP_ */ diff --git a/workspace/TS100/inc/MMA8652FC.hpp b/workspace/TS100/inc/MMA8652FC.hpp index 84f9fb0e..7bf1cafa 100644 --- a/workspace/TS100/inc/MMA8652FC.hpp +++ b/workspace/TS100/inc/MMA8652FC.hpp @@ -16,17 +16,12 @@ class MMA8652FC { public: - MMA8652FC(FRToSI2C* i2cHandle) : i2c(i2cHandle) {} - void initalize(); // Initalize the system - Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left) - void getAxisReadings(int16_t *x, int16_t *y, int16_t *z); + + static void initalize(); // Initalize the system + static Orientation getOrientation();// Reads the I2C register and returns the orientation (true == left) + static void getAxisReadings(int16_t *x, int16_t *y, int16_t *z); private: - - void I2C_RegisterWrite(uint8_t reg, uint8_t data); - uint8_t I2C_RegisterRead(uint8_t reg); - FRToSI2C* i2c; - }; #endif /* MMA8652FC_HPP_ */ diff --git a/workspace/TS100/inc/OLED.hpp b/workspace/TS100/inc/OLED.hpp index cbf3eecc..095e17d4 100644 --- a/workspace/TS100/inc/OLED.hpp +++ b/workspace/TS100/inc/OLED.hpp @@ -26,79 +26,83 @@ extern "C" { #define OLED_WIDTH 96 #define FRAMEBUFFER_START 17 - class OLED { public: - OLED(FRToSI2C* i2cHandle); // Initialize Driver and store I2C pointer - void initialize(); // Startup the I2C coms (brings screen out of reset etc) - + static void initialize(); // Startup the I2C coms (brings screen out of reset etc) + // Draw the buffer out to the LCD using the DMA Channel - void refresh() { - i2c->Transmit( DEVICEADDR_OLED, screenBuffer, FRAMEBUFFER_START + (OLED_WIDTH * 2)); + static void refresh() { + FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer, + FRAMEBUFFER_START + (OLED_WIDTH * 2)); //DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms //or we need to goto double buffering } - void drawChar(char c, char preCursorCommand = '\0'); // Draw a character to a specific location + static void drawChar(char c, char preCursorCommand = '\0'); // Draw a character to a specific location // Turn the screen on or not - void displayOnOff(bool on) { + static void displayOnOff(bool on) { displayOnOffState = on; screenBuffer[1] = on ? 0xAF : 0xAE; - } - void setRotation(bool leftHanded); // Set the rotation for the screen + } + static void setRotation(bool leftHanded); // Set the rotation for the screen // Get the current rotation of the LCD - bool getRotation() const { + static bool getRotation() { return inLeftHandedMode; - } - void print(const char* string); // Draw a string to the current location, with current font + } + static int16_t getCursorX() { + return cursor_x; + } + static void print(const char* string);// Draw a string to the current location, with current font // Set the cursor location by pixels - void setCursor(int16_t x, int16_t y) { + static void setCursor(int16_t x, int16_t y) { cursor_x = x; - cursor_y = y; - } + cursor_y = y; + } //Set cursor location by chars in current font - void setCharCursor(int16_t x, int16_t y) { + static void setCharCursor(int16_t x, int16_t y) { cursor_x = x * fontWidth; cursor_y = y * fontHeight; } - void setFont(uint8_t fontNumber); // (Future) Set the font that is being used - void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) { + static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used + static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) { drawArea(x, 0, width, 16, buffer); } // Draws an image to the buffer, at x offset from top to bottom (fixed height renders) - void printNumber(uint16_t number, uint8_t places); + static void printNumber(uint16_t number, uint8_t places); // Draws a number at the current cursor location // Clears the buffer - void clearScreen() { + static void clearScreen() { memset(&screenBuffer[FRAMEBUFFER_START], 0, OLED_WIDTH * 2); - } + } // Draws the battery level symbol - void drawBattery(uint8_t state) { + static void drawBattery(uint8_t state) { drawSymbol(3 + (state > 10 ? 10 : state)); - } + } // Draws a checkbox - void drawCheckbox(bool state) { + static void drawCheckbox(bool state) { drawSymbol((state) ? 16 : 17); } - void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width - void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset - void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset - void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,bool clear); - void drawHeatSymbol(uint8_t state); + static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width + static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, + const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset + static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, + const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset + static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, + bool clear); + static void drawHeatSymbol(uint8_t state); private: //Draw a buffer to the screen buffer - FRToSI2C* i2c; //i2c Pointer - const uint8_t* currentFont; // Pointer to the current font used for rendering to the buffer - uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content - uint8_t* secondStripPtr; //Pointers to the strips - bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM) - bool displayOnOffState; // If the display is on or not - uint8_t fontWidth, fontHeight; - int16_t cursor_x, cursor_y; - uint8_t displayOffset; - uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer + static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer + static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content + static uint8_t* secondStripPtr; //Pointers to the strips + static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM) + static bool displayOnOffState; // If the display is on or not + static uint8_t fontWidth, fontHeight; + static int16_t cursor_x, cursor_y; + static uint8_t displayOffset; + static uint8_t screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer }; #endif /* OLED_HPP_ */ diff --git a/workspace/TS100/inc/Settings.h b/workspace/TS100/inc/Settings.h index 8d653943..65dccd67 100644 --- a/workspace/TS100/inc/Settings.h +++ b/workspace/TS100/inc/Settings.h @@ -11,36 +11,45 @@ #define SETTINGS_H_ #include #include "stm32f1xx_hal.h" -#define SETTINGSVERSION 0x15 /*Change this if you change the struct below to prevent people getting out of sync*/ +#define SETTINGSVERSION \ + 0x16 /*Change this if you change the struct below to prevent people getting \ + out of sync*/ /* - * This struct must be a multiple of 2 bytes as it is saved / restored from flash in uint16_t chunks + * This struct must be a multiple of 2 bytes as it is saved / restored from + * flash in uint16_t chunks */ typedef struct { - uint16_t SolderingTemp; //current set point for the iron - uint16_t SleepTemp; //temp to drop to in sleep - uint8_t SleepTime; //minutes timeout to sleep - uint8_t cutoutSetting; // The voltage we cut out at for under voltage - uint8_t OrientationMode:2; //If true we want to invert the display for lefties - uint8_t sensitivity :4; //Sensitivity of accelerometer (5 bits) - uint8_t autoStartMode :2; //Should the unit automatically jump straight into soldering mode when power is applied - uint8_t ShutdownTime; //Time until unit shuts down if left alone - uint8_t boostModeEnabled :1; //Boost mode swaps BUT_A in soldering mode to temporary soldering temp over-ride - uint8_t coolingTempBlink :1; //Should the temperature blink on the cool down screen until its <50C - uint8_t detailedIDLE :1; //Detailed idle screen - uint8_t detailedSoldering :1; //Detailed soldering screens - uint8_t temperatureInF; //Should the temp be in F or C (true is F) - uint8_t descriptionScrollSpeed:1; // Description scroll speed - uint16_t voltageDiv; //Voltage divisor factor - uint16_t BoostTemp; //Boost mode set point for the iron - int16_t CalibrationOffset; //This stores the temperature offset for this tip in the iron. - uint8_t PID_P; //PID P Term - uint8_t PID_I; //PID I Term - uint8_t PID_D; //PID D Term - uint8_t version; //Used to track if a reset is needed on firmware upgrade - uint8_t customTipGain; // Tip gain value if custom tuned, or 0 if using a tipType param + uint16_t SolderingTemp; // current set point for the iron + uint16_t SleepTemp; // temp to drop to in sleep + uint8_t SleepTime; // minutes timeout to sleep + uint8_t cutoutSetting; // The voltage we cut out at for under voltage OR Power level for TS80 + uint8_t OrientationMode :2; // If true we want to invert the display for lefties + uint8_t sensitivity :4; // Sensitivity of accelerometer (5 bits) + uint8_t autoStartMode :2; // Should the unit automatically jump straight + // into soldering mode when power is applied + uint8_t ShutdownTime; // Time until unit shuts down if left alone + uint8_t boostModeEnabled :1; // Boost mode swaps BUT_A in soldering mode to + // temporary soldering temp over-ride + uint8_t coolingTempBlink :1; // Should the temperature blink on the cool + // down screen until its <50C + uint8_t detailedIDLE :1; // Detailed idle screen + uint8_t detailedSoldering :1; // Detailed soldering screens + uint8_t temperatureInF; // Should the temp be in F or C (true is F) + uint8_t descriptionScrollSpeed :1; // Description scroll speed + uint16_t voltageDiv; // Voltage divisor factor + uint16_t BoostTemp; // Boost mode set point for the iron + int16_t CalibrationOffset; // This stores the temperature offset for this tip + // in the iron. + uint8_t PID_P; // PID P Term + uint8_t PID_I; // PID I Term + uint8_t PID_D; // PID D Term + uint8_t version; // Used to track if a reset is needed on firmware upgrade + uint8_t customTipGain; // Tip gain value if custom tuned, or 0 if using a + // tipType param uint8_t tipType; - uint32_t padding; //This is here for in case we are not an even divisor so that nothing gets cut off + uint32_t padding; // This is here for in case we are not an even divisor so + // that nothing gets cut off } systemSettingsType; extern volatile systemSettingsType systemSettings; diff --git a/workspace/TS100/inc/Translation.h b/workspace/TS100/inc/Translation.h index b5030744..afb1dcc2 100644 --- a/workspace/TS100/inc/Translation.h +++ b/workspace/TS100/inc/Translation.h @@ -9,7 +9,8 @@ #define TRANSLATION_H_ enum ShortNameType { - SHORT_NAME_SINGLE_LINE = 1, SHORT_NAME_DOUBLE_LINE = 2, + SHORT_NAME_SINGLE_LINE = 1, + SHORT_NAME_DOUBLE_LINE = 2, }; /* @@ -17,10 +18,9 @@ enum ShortNameType { * use SettingsShortNames as SettingsShortNames[16][1].. second column undefined */ extern const enum ShortNameType SettingsShortNameType; -extern const char* SettingsShortNames[][2]; -extern const char* SettingsDescriptions[]; +extern const char* SettingsShortNames[21][2]; +extern const char* SettingsDescriptions[21]; extern const char* SettingsMenuEntries[4]; -extern const char* SettingsMenuEntriesDescriptions[4]; extern const char* SettingsCalibrationDone; extern const char* SettingsCalibrationWarning; diff --git a/workspace/TS100/inc/hardware.h b/workspace/TS100/inc/hardware.h index 6d945b3f..aa6de11d 100644 --- a/workspace/TS100/inc/hardware.h +++ b/workspace/TS100/inc/hardware.h @@ -7,36 +7,38 @@ #ifndef HARDWARE_H_ #define HARDWARE_H_ -#include "stm32f1xx_hal.h" #include "Setup.h" +#include "stm32f1xx_hal.h" #ifdef __cplusplus extern "C" { #endif enum Orientation { - ORIENTATION_LEFT_HAND = 0, ORIENTATION_RIGHT_HAND = 1, ORIENTATION_FLAT = 3 -}; -/* - * Keep in a uint8_t range for the ID's - */ -enum TipType { - TS_B2 = 0, - TS_D24 = 1, - TS_BC2 = 2, - TS_C1 = 3, - Tip_MiniWare=4, - HAKKO_BC2=4, - Tip_Hakko=5, - Tip_Custom=5, + ORIENTATION_LEFT_HAND = 0, + ORIENTATION_RIGHT_HAND = 1, + ORIENTATION_FLAT = 3 }; +#ifndef MODEL_TS100 + #ifndef MODEL_TS80 +#error "Please Define the model you are building for! MODEL=TS100 or MODEL=TS80" + #endif +#endif + +#ifdef MODEL_TS100 + #define KEY_B_Pin GPIO_PIN_6 #define KEY_B_GPIO_Port GPIOA #define TMP36_INPUT_Pin GPIO_PIN_7 #define TMP36_INPUT_GPIO_Port GPIOA +#define TMP36_ADC1_CHANNEL ADC_CHANNEL_7 #define TIP_TEMP_Pin GPIO_PIN_0 #define TIP_TEMP_GPIO_Port GPIOB +#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_8 +#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_8 #define VIN_Pin GPIO_PIN_1 #define VIN_GPIO_Port GPIOB +#define VIN_ADC1_CHANNEL ADC_CHANNEL_9 +#define VIN_ADC2_CHANNEL ADC_CHANNEL_9 #define OLED_RESET_Pin GPIO_PIN_8 #define OLED_RESET_GPIO_Port GPIOA #define KEY_A_Pin GPIO_PIN_9 @@ -45,6 +47,8 @@ enum TipType { #define INT_Orientation_GPIO_Port GPIOB #define PWM_Out_Pin GPIO_PIN_4 #define PWM_Out_GPIO_Port GPIOB +#define PWM_Out_CHANNEL TIM_CHANNEL_1 +#define PWM_Out_CCR #define INT_Movement_Pin GPIO_PIN_5 #define INT_Movement_GPIO_Port GPIOB #define SCL_Pin GPIO_PIN_6 @@ -52,6 +56,64 @@ enum TipType { #define SDA_Pin GPIO_PIN_7 #define SDA_GPIO_Port GPIOB +#else +// TS80 pin map +#define KEY_B_Pin GPIO_PIN_0 +#define KEY_B_GPIO_Port GPIOB +#define TMP36_INPUT_Pin GPIO_PIN_4 +#define TMP36_INPUT_GPIO_Port GPIOA +#define TMP36_ADC1_CHANNEL ADC_CHANNEL_4 +#define TIP_TEMP_Pin GPIO_PIN_3 +#define TIP_TEMP_GPIO_Port GPIOA +#define TIP_TEMP_ADC1_CHANNEL ADC_CHANNEL_3 +#define TIP_TEMP_ADC2_CHANNEL ADC_CHANNEL_3 + +#define VIN_Pin GPIO_PIN_2 +#define VIN_GPIO_Port GPIOA +#define VIN_ADC1_CHANNEL ADC_CHANNEL_2 +#define VIN_ADC2_CHANNEL ADC_CHANNEL_2 +#define OLED_RESET_Pin GPIO_PIN_15 +#define OLED_RESET_GPIO_Port GPIOA +#define KEY_A_Pin GPIO_PIN_1 +#define KEY_A_GPIO_Port GPIOB +#define INT_Orientation_Pin GPIO_PIN_4 +#define INT_Orientation_GPIO_Port GPIOB +#define PWM_Out_Pin GPIO_PIN_6 +#define PWM_Out_GPIO_Port GPIOA +#define PWM_Out_CHANNEL TIM_CHANNEL_1 +#define INT_Movement_Pin GPIO_PIN_5 +#define INT_Movement_GPIO_Port GPIOB +#define SCL_Pin GPIO_PIN_6 +#define SCL_GPIO_Port GPIOB +#define SDA_Pin GPIO_PIN_7 +#define SDA_GPIO_Port GPIOB + +#endif + +/* + * Keep in a uint8_t range for the ID's + */ +#ifdef MODEL_TS100 +enum TipType { + TS_B2 = 0, + TS_D24 = 1, + TS_BC2 = 2, + TS_C1 = 3, + Tip_MiniWare = 4, + HAKKO_BC2 = 4, + Tip_Hakko = 5, + Tip_Custom = 5, +}; +#endif +#ifdef MODEL_TS80 +enum TipType { + TS_B02 = 0, + TS_D25 = 1, + Tip_MiniWare = 2, + Tip_Custom = 2, +}; +#endif + uint16_t getHandleTemperature(); uint16_t getTipRawTemp(uint8_t instant); uint16_t getInputVoltageX10(uint16_t divisor); @@ -62,9 +124,17 @@ uint16_t ctoTipMeasurement(uint16_t temp); uint16_t tipMeasurementToC(uint16_t raw); uint16_t ftoTipMeasurement(uint16_t temp); uint16_t tipMeasurementToF(uint16_t raw); - +void seekQC(int16_t Vx10); void setCalibrationOffset(int16_t offSet); void setTipType(enum TipType tipType, uint8_t manualCalGain); +uint32_t calculateTipR(uint8_t useFilter); +int16_t calculateMaxVoltage(uint8_t useFilter, uint8_t useHP); +void startQC(); // Tries to negotiate QC for highest voltage, must be run after + // RToS +// This will try for 12V, failing that 9V, failing that 5V +// If input is over 12V returns -1 +// If the input is [5-12] Will return the value. + #ifdef __cplusplus } #endif diff --git a/workspace/TS100/inc/main.hpp b/workspace/TS100/inc/main.hpp index f91bf0a4..f83933a5 100644 --- a/workspace/TS100/inc/main.hpp +++ b/workspace/TS100/inc/main.hpp @@ -2,25 +2,23 @@ #define __MAIN_H #include -#include "Setup.h" #include "OLED.hpp" -extern uint16_t currentlyActiveTemperatureTarget; -extern OLED lcd; -extern MMA8652FC accel; +#include "Setup.h" extern uint8_t PCBVersion; +extern uint16_t currentlyActiveTemperatureTarget; enum ButtonState { - BUTTON_NONE = 0, /* No buttons pressed / < filter time*/ - BUTTON_F_SHORT = 1, /* User has pressed the front button*/ - BUTTON_B_SHORT = 2, /* User has pressed the back button*/ - BUTTON_F_LONG = 4, /* User is holding the front button*/ - BUTTON_B_LONG = 8, /* User is holding the back button*/ - BUTTON_BOTH = 16, /* User has pressed both buttons*/ + BUTTON_NONE = 0, /* No buttons pressed / < filter time*/ + BUTTON_F_SHORT = 1, /* User has pressed the front button*/ + BUTTON_B_SHORT = 2, /* User has pressed the back button*/ + BUTTON_F_LONG = 4, /* User is holding the front button*/ + BUTTON_B_LONG = 8, /* User is holding the back button*/ + BUTTON_BOTH = 16, /* User has pressed both buttons*/ -/* - * Note: - * Pressed means press + release, we trigger on a full \__/ pulse - * holding means it has gone low, and been low for longer than filter time - */ + /* + * Note: + * Pressed means press + release, we trigger on a full \__/ pulse + * holding means it has gone low, and been low for longer than filter time + */ }; ButtonState getButtonState(); @@ -31,15 +29,15 @@ void GUIDelay(); extern "C" { #endif -void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc); +void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc); void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); -void vApplicationStackOverflowHook( xTaskHandle *pxTask, - signed portCHAR *pcTaskName); +void vApplicationStackOverflowHook(xTaskHandle *pxTask, + signed portCHAR *pcTaskName); #ifdef __cplusplus } diff --git a/workspace/TS100/src/FRToSI2C.cpp b/workspace/TS100/src/FRToSI2C.cpp index b50f86d2..1acc532e 100644 --- a/workspace/TS100/src/FRToSI2C.cpp +++ b/workspace/TS100/src/FRToSI2C.cpp @@ -7,82 +7,85 @@ #include "FRToSI2C.hpp" -void __attribute__ ((long_call, section (".data.ramfuncs"))) FRToSI2C::CpltCallback() { - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - i2c->State = HAL_I2C_STATE_READY;//Force state reset - if (I2CSemaphore) { - xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken); - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); - } +I2C_HandleTypeDef* FRToSI2C::i2c; +SemaphoreHandle_t FRToSI2C::I2CSemaphore; +void FRToSI2C::CpltCallback() { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + i2c->State = HAL_I2C_STATE_READY; // Force state reset (even if tx error) + if (I2CSemaphore) { + xSemaphoreGiveFromISR(I2CSemaphore, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } } void FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, - uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { - if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || I2CSemaphore == NULL) { - //no RToS, run blocking code - HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, - 5000); - } else { - //RToS is active, run threading - //Get the mutex so we can use the I2C port - //Wait up to 1 second for the mutex - if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) { - if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, - Size, 5000) != HAL_OK) { - NVIC_SystemReset(); - } - xSemaphoreGive(I2CSemaphore); - } else { - NVIC_SystemReset(); - } - - } - + uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { + if (I2CSemaphore == NULL) { + // no RToS, run blocking code + HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, + 5000); + } else { + // RToS is active, run threading + // Get the mutex so we can use the I2C port + // Wait up to 1 second for the mutex + if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) { + if (HAL_I2C_Mem_Read(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, + 5000) != HAL_OK) { + NVIC_SystemReset(); + } + xSemaphoreGive(I2CSemaphore); + } else { + NVIC_SystemReset(); + } + } +} +void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { + Mem_Write(address, reg, I2C_MEMADD_SIZE_8BIT, &data, 1); } +uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) { + uint8_t tx_data[1]; + Mem_Read(add, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1); + return tx_data[0]; +} void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, - uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { - if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || I2CSemaphore == NULL) { - //no RToS, run blocking code - HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, - 5000); - } else { - //RToS is active, run threading - //Get the mutex so we can use the I2C port - //Wait up to 1 second for the mutex - if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) { - if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, - pData, Size, 5000) != HAL_OK) { - NVIC_SystemReset(); - } - xSemaphoreGive(I2CSemaphore); + uint16_t MemAddSize, uint8_t* pData, uint16_t Size) { + if (I2CSemaphore == NULL) { + // no RToS, run blocking code + HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, Size, + 5000); + } else { + // RToS is active, run threading + // Get the mutex so we can use the I2C port + // Wait up to 1 second for the mutex + if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) { + if (HAL_I2C_Mem_Write(i2c, DevAddress, MemAddress, MemAddSize, pData, + Size, 5000) != HAL_OK) { + NVIC_SystemReset(); + } + xSemaphoreGive(I2CSemaphore); - } else { - NVIC_SystemReset(); - } - } + } else { + NVIC_SystemReset(); + } + } } void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t* pData, uint16_t Size) { - if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED - || I2CSemaphore == NULL) { - //no RToS, run blocking code - HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000); - } else { - //RToS is active, run threading - //Get the mutex so we can use the I2C port - //Wait up to 1 second for the mutex - if ( xSemaphoreTake( I2CSemaphore, ( TickType_t ) 5000 ) == pdTRUE) { - if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) - != HAL_OK) { - NVIC_SystemReset(); - } - //xSemaphoreGive(I2CSemaphore); - } else { - NVIC_SystemReset(); - } - } - + if (I2CSemaphore == NULL) { + // no RToS, run blocking code + HAL_I2C_Master_Transmit(i2c, DevAddress, pData, Size, 5000); + } else { + // RToS is active, run threading + // Get the mutex so we can use the I2C port + // Wait up to 1 second for the mutex + if (xSemaphoreTake(I2CSemaphore, (TickType_t)5000) == pdTRUE) { + if (HAL_I2C_Master_Transmit_DMA(i2c, DevAddress, pData, Size) != HAL_OK) { + NVIC_SystemReset(); + } + // xSemaphoreGive(I2CSemaphore); + } else { + NVIC_SystemReset(); + } + } } diff --git a/workspace/TS100/src/LIS2DH12.cpp b/workspace/TS100/src/LIS2DH12.cpp index 40f9be53..544ead40 100644 --- a/workspace/TS100/src/LIS2DH12.cpp +++ b/workspace/TS100/src/LIS2DH12.cpp @@ -8,6 +8,7 @@ #include #include "cmsis_os.h" + typedef struct { const uint8_t reg; const uint8_t value; @@ -31,13 +32,13 @@ static const LIS_REG i2c_registers[] = { void LIS2DH12::initalize() { for (size_t index = 0; index < (sizeof(i2c_registers) / sizeof(i2c_registers[0])); index++) { - I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].value); + FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].value); } } void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) { uint8_t tempArr[6]; - i2c->Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT, +FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6); (*x) = ((uint16_t) (tempArr[1] << 8 | tempArr[0])); @@ -45,13 +46,4 @@ void LIS2DH12::getAxisReadings(int16_t* x, int16_t* y, int16_t* z) { (*z) = ((uint16_t) (tempArr[5] << 8 | tempArr[4])); } -void LIS2DH12::I2C_RegisterWrite(uint8_t reg, uint8_t data) { - i2c->Mem_Write(LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1); -} - -uint8_t LIS2DH12::I2C_RegisterRead(uint8_t reg) { - uint8_t tx_data[1]; - i2c->Mem_Read( LIS2DH_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data, 1); - return tx_data[0]; -} diff --git a/workspace/TS100/src/MMA8652FC.cpp b/workspace/TS100/src/MMA8652FC.cpp index 5825a880..a6757604 100644 --- a/workspace/TS100/src/MMA8652FC.cpp +++ b/workspace/TS100/src/MMA8652FC.cpp @@ -9,55 +9,47 @@ #include "cmsis_os.h" typedef struct { - const uint8_t reg; - const uint8_t val; + const uint8_t reg; + const uint8_t val; } MMA_REG; -static const MMA_REG i2c_registers[] = { - {CTRL_REG2, 0}, //Normal mode - {CTRL_REG2, 0x40}, // Reset all registers to POR values - {FF_MT_CFG_REG, 0x78}, // Enable motion detection for X, Y, Z axis, latch disabled - {PL_CFG_REG, 0x40}, //Enable the orientation detection - {PL_COUNT_REG, 200}, //200 count debounce - {PL_BF_ZCOMP_REG, 0b01000111}, //Set the threshold to 42 degrees - {P_L_THS_REG, 0b10011100}, //Up the trip angles - {CTRL_REG4, 0x01 | (1 << 4)}, // Enable dataready interrupt & orientation interrupt - {CTRL_REG5, 0x01}, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2 - {CTRL_REG2, 0x12}, //Set maximum resolution oversampling - {XYZ_DATA_CFG_REG, (1 << 4)}, //select high pass filtered data - {HP_FILTER_CUTOFF_REG, 0x03}, //select high pass filtered data - {CTRL_REG1, 0x19} // ODR=12 Hz, Active mode +static const MMA_REG i2c_registers[] = { { CTRL_REG2, 0 }, //Normal mode + { CTRL_REG2, 0x40 }, // Reset all registers to POR values + { FF_MT_CFG_REG, 0x78 }, // Enable motion detection for X, Y, Z axis, latch disabled + { PL_CFG_REG, 0x40 }, //Enable the orientation detection + { PL_COUNT_REG, 200 }, //200 count debounce + { PL_BF_ZCOMP_REG, 0b01000111 }, //Set the threshold to 42 degrees + { P_L_THS_REG, 0b10011100 }, //Up the trip angles + { CTRL_REG4, 0x01 | (1 << 4) }, // Enable dataready interrupt & orientation interrupt + { CTRL_REG5, 0x01 }, // Route data ready interrupts to INT1 ->PB5 ->EXTI5, leaving orientation routed to INT2 + { CTRL_REG2, 0x12 }, //Set maximum resolution oversampling + { XYZ_DATA_CFG_REG, (1 << 4) }, //select high pass filtered data + { HP_FILTER_CUTOFF_REG, 0x03 }, //select high pass filtered data + { CTRL_REG1, 0x19 } // ODR=12 Hz, Active mode }; -void MMA8652FC::I2C_RegisterWrite(uint8_t reg, uint8_t data) { - i2c->Mem_Write( MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, &data, 1); -} -uint8_t MMA8652FC::I2C_RegisterRead(uint8_t reg) { - uint8_t tx_data[1]; - i2c->Mem_Read( MMA8652FC_I2C_ADDRESS, reg, I2C_MEMADD_SIZE_8BIT, tx_data, - 1); - - return tx_data[0]; -} void MMA8652FC::initalize() { size_t index = 0; //send all the init commands to the unit - I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++; - I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++; + FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val); + index++; + FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val); + index++; HAL_Delay(2); // ~1ms delay while (index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]))) { - I2C_RegisterWrite(i2c_registers[index].reg, i2c_registers[index].val); index++; + FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,i2c_registers[index].reg, i2c_registers[index].val); + index++; } } Orientation MMA8652FC::getOrientation() { //First read the PL_STATUS register - uint8_t plStatus = I2C_RegisterRead(PL_STATUS_REG); + uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS,PL_STATUS_REG); if ((plStatus & 0b10000000) == 0b10000000) { plStatus >>= 1; //We don't need the up/down bit plStatus &= 0x03; //mask to the two lower bits @@ -67,12 +59,13 @@ Orientation MMA8652FC::getOrientation() { return static_cast(plStatus); } - + return ORIENTATION_FLAT; } void MMA8652FC::getAxisReadings(int16_t *x, int16_t *y, int16_t *z) { uint8_t tempArr[6]; - i2c->Mem_Read( MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,I2C_MEMADD_SIZE_8BIT, (uint8_t*) tempArr, 6); + FRToSI2C::Mem_Read( MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG, I2C_MEMADD_SIZE_8BIT, + (uint8_t*) tempArr, 6); (*x) = tempArr[0] << 8 | tempArr[1]; (*y) = tempArr[2] << 8 | tempArr[3]; diff --git a/workspace/TS100/src/OLED.cpp b/workspace/TS100/src/OLED.cpp index 6c638ae6..17067208 100644 --- a/workspace/TS100/src/OLED.cpp +++ b/workspace/TS100/src/OLED.cpp @@ -5,69 +5,81 @@ * Author: Ben V. Brown */ -#include #include +#include #include "Translation.h" #include "cmsis_os.h" + +const uint8_t* OLED::currentFont; // Pointer to the current font used for + // rendering to the buffer +uint8_t* OLED::firstStripPtr; // Pointers to the strips to allow for buffer + // having extra content +uint8_t* OLED::secondStripPtr; // Pointers to the strips +bool OLED::inLeftHandedMode; // Whether the screen is in left or not (used for + // offsets in GRAM) +bool OLED::displayOnOffState; // If the display is on or not +uint8_t OLED::fontWidth, OLED::fontHeight; +int16_t OLED::cursor_x, OLED::cursor_y; +uint8_t OLED::displayOffset; +uint8_t OLED::screenBuffer[16 + (OLED_WIDTH * 2) + 10]; // The data buffer + /*Setup params for the OLED screen*/ /*http://www.displayfuture.com/Display/datasheet/controller/SSD1307.pdf*/ /*All commands are prefixed with 0x80*/ /*Data packets are prefixed with 0x40*/ -uint8_t OLED_Setup_Array[] = { /**/ -0x80, 0xAE,/*Display off*/ -0x80, 0xD5,/*Set display clock divide ratio / osc freq*/ -0x80, 0x52,/*Divide ratios*/ -0x80, 0xA8,/*Set Multiplex Ratio*/ -0x80, 0x0F,/*16 == max brightness,39==dimmest*/ -0x80, 0xC0,/*Set COM Scan direction*/ -0x80, 0xD3,/*Set vertical Display offset*/ -0x80, 0x00,/*0 Offset*/ -0x80, 0x40,/*Set Display start line to 0*/ -0x80, 0xA0,/*Set Segment remap to normal*/ -0x80, 0x8D,/*Charge Pump*/ -0x80, 0x14,/*Charge Pump settings*/ -0x80, 0xDA,/*Set VCOM Pins hardware config*/ -0x80, 0x02,/*Combination 2*/ -0x80, 0x81,/*Contrast*/ -0x80, 0x33,/*^51*/ -0x80, 0xD9,/*Set pre-charge period*/ -0x80, 0xF1,/*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*/ +uint8_t OLED_Setup_Array[] = { + /**/ + 0x80, 0xAE, /*Display off*/ + 0x80, 0xD5, /*Set display clock divide ratio / osc freq*/ + 0x80, 0x52, /*Divide ratios*/ + 0x80, 0xA8, /*Set Multiplex Ratio*/ + 0x80, 0x0F, /*16 == max brightness,39==dimmest*/ + 0x80, 0xC0, /*Set COM Scan direction*/ + 0x80, 0xD3, /*Set vertical Display offset*/ + 0x80, 0x00, /*0 Offset*/ + 0x80, 0x40, /*Set Display start line to 0*/ + 0x80, 0xA0, /*Set Segment remap to normal*/ + 0x80, 0x8D, /*Charge Pump*/ + 0x80, 0x14, /*Charge Pump settings*/ + 0x80, 0xDA, /*Set VCOM Pins hardware config*/ + 0x80, 0x02, /*Combination 2*/ + 0x80, 0x81, /*Contrast*/ + 0x80, 0x33, /*^51*/ + 0x80, 0xD9, /*Set pre-charge period*/ + 0x80, 0xF1, /*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*/ }; -//Setup based on the SSD1307 and modified for the SSD1306 +// Setup based on the SSD1307 and modified for the SSD1306 -const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80, - 0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 }; - -OLED::OLED(FRToSI2C* i2cHandle) { - i2c = i2cHandle; - cursor_x = cursor_y = 0; - currentFont = FONT_12; - fontWidth = 12; - inLeftHandedMode = false; - firstStripPtr = &screenBuffer[FRAMEBUFFER_START]; - secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH]; - fontHeight = 16; - displayOffset = 0; - displayOnOffState = true; -} +const uint8_t REFRESH_COMMANDS[17] = {0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, + 0x80, 0x7F, 0x80, 0xC0, 0x80, 0x22, + 0x80, 0x00, 0x80, 0x01, 0x40}; void OLED::initialize() { - memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS)); + cursor_x = cursor_y = 0; + currentFont = FONT_12; + fontWidth = 12; + inLeftHandedMode = false; + firstStripPtr = &screenBuffer[FRAMEBUFFER_START]; + secondStripPtr = &screenBuffer[FRAMEBUFFER_START + OLED_WIDTH]; + fontHeight = 16; + displayOffset = 0; + displayOnOffState = true; + memcpy(&screenBuffer[0], &REFRESH_COMMANDS[0], sizeof(REFRESH_COMMANDS)); - HAL_Delay(50); - HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET); - HAL_Delay(50); - //Send the setup settings - i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, - sizeof(OLED_Setup_Array)); - displayOnOff(true); + HAL_Delay(50); + HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET); + HAL_Delay(50); + // Send the setup settings + FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*)OLED_Setup_Array, + sizeof(OLED_Setup_Array)); + displayOnOff(true); } /* @@ -76,259 +88,262 @@ void OLED::initialize() { * Precursor is the command char that is used to select the table. */ void OLED::drawChar(char c, char PrecursorCommand) { - if (c == '\n' && cursor_y == 0) { - cursor_x = 0; - cursor_y = 8; - } - if (c < ' ') { - return; - } - uint16_t index = 0; - if (PrecursorCommand == 0) { - //Fonts are offset to start at the space char - index = (c - ' '); - } else { - //This is for extended range - //We decode the precursor command to find the offset - //Latin starts at 96 - c -= 0x80; + if (c == '\n' && cursor_y == 0) { + cursor_x = 0; + cursor_y = 8; + } + if (c < ' ') { + return; + } + uint16_t index = 0; + if (PrecursorCommand == 0) { + // Fonts are offset to start at the space char + index = (c - ' '); + } else { + // This is for extended range + // We decode the precursor command to find the offset + // Latin starts at 96 + c -= 0x80; - switch (PrecursorCommand) { - - case 0xC2: - index = (96 - 32) + (c); - break; //-32 compensate for chars excluded from font C2 section - case 0xC3: - index = (128) + (c); - break; -#if defined(LANG_RU) || defined(LANG_UK) || defined(LANG_SR) || defined(LANG_BG) || defined(LANG_MK) - case 0xD0: - index = (192) + (c); - break; - case 0xD1: - index = (256) + (c); - break; + switch (PrecursorCommand) { + case 0xC2: + index = (96 - 32) + (c); + break; //-32 compensate for chars excluded from font C2 section + case 0xC3: + index = (128) + (c); + break; +#if defined(LANG_RU) || defined(LANG_UK) || defined(LANG_SR) || \ + defined(LANG_BG) || defined(LANG_MK) + case 0xD0: + index = (192) + (c); + break; + case 0xD1: + index = (256) + (c); + break; #else - case 0xC4: - index = (192) + (c); - break; - case 0xC5: - index = (256) + (c); - break; + case 0xC4: + index = (192) + (c); + break; + case 0xC5: + index = (256) + (c); + break; #endif - default: - return; - } - } - uint8_t* charPointer; - charPointer = ((uint8_t*) currentFont) - + ((fontWidth * (fontHeight / 8)) * index); + default: + return; + } + } + uint8_t* charPointer; + charPointer = + ((uint8_t*)currentFont) + ((fontWidth * (fontHeight / 8)) * index); - drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer); + drawArea(cursor_x, cursor_y, fontWidth, fontHeight, charPointer); - cursor_x += fontWidth; + cursor_x += fontWidth; } void OLED::setRotation(bool leftHanded) { - if (inLeftHandedMode == leftHanded) { - return; - } + if (inLeftHandedMode == leftHanded) { + return; + } - //send command struct again with changes - if (leftHanded) { - OLED_Setup_Array[11] = 0xC8; //c1? - OLED_Setup_Array[19] = 0xA1; - } else { - OLED_Setup_Array[11] = 0xC0; - OLED_Setup_Array[19] = 0xA0; - } - i2c->Transmit( DEVICEADDR_OLED, (uint8_t*) OLED_Setup_Array, - sizeof(OLED_Setup_Array)); - inLeftHandedMode = leftHanded; + // send command struct again with changes + if (leftHanded) { + OLED_Setup_Array[11] = 0xC8; // c1? + OLED_Setup_Array[19] = 0xA1; + } else { + OLED_Setup_Array[11] = 0xC0; + OLED_Setup_Array[19] = 0xA0; + } + FRToSI2C::Transmit(DEVICEADDR_OLED, (uint8_t*)OLED_Setup_Array, + sizeof(OLED_Setup_Array)); + inLeftHandedMode = leftHanded; - screenBuffer[5] = inLeftHandedMode ? 0 : 32; //display is shifted by 32 in left handed mode as driver ram is 128 wide - screenBuffer[7] = inLeftHandedMode ? 95 : 0x7F; //End address of the ram segment we are writing to (96 wide) - screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0; + screenBuffer[5] = + inLeftHandedMode ? 0 : 32; // display is shifted by 32 in left handed + // mode as driver ram is 128 wide + screenBuffer[7] = + inLeftHandedMode + ? 95 + : 0x7F; // End address of the ram segment we are writing to (96 wide) + screenBuffer[9] = inLeftHandedMode ? 0xC8 : 0xC0; } -//print a string to the current cursor location +// print a string to the current cursor location void OLED::print(const char* str) { - while (str[0]) { - if (str[0] >= 0x80) { - drawChar(str[1], str[0]); - str++; //skip this marker - } else - drawChar(str[0]); - str++; - } + while (str[0]) { + if (str[0] >= 0x80) { + drawChar(str[1], str[0]); + str++; // skip this marker + } else + drawChar(str[0]); + str++; + } } void OLED::setFont(uint8_t fontNumber) { - if (fontNumber == 1) { - //small font - currentFont = FONT_6x8; - fontHeight = 8; - fontWidth = 6; - } else if (fontNumber == 2) { - currentFont = ExtraFontChars; - fontHeight = 16; - fontWidth = 12; - } else { - currentFont = FONT_12; - fontHeight = 16; - fontWidth = 12; - } + if (fontNumber == 1) { + // small font + currentFont = FONT_6x8; + fontHeight = 8; + fontWidth = 6; + } else if (fontNumber == 2) { + currentFont = ExtraFontChars; + fontHeight = 16; + fontWidth = 12; + } else { + currentFont = FONT_12; + fontHeight = 16; + fontWidth = 12; + } } -//maximum places is 5 +// maximum places is 5 void OLED::printNumber(uint16_t number, uint8_t places) { - char buffer[7] = { 0 }; + char buffer[7] = {0}; - if (places >= 5) { - buffer[5] = '0' + number % 10; - number /= 10; - } - if (places > 4) { - buffer[4] = '0' + number % 10; - number /= 10; - } + if (places >= 5) { + buffer[5] = '0' + number % 10; + number /= 10; + } + if (places > 4) { + buffer[4] = '0' + number % 10; + number /= 10; + } - if (places > 3) { - buffer[3] = '0' + number % 10; - number /= 10; - } + if (places > 3) { + buffer[3] = '0' + number % 10; + number /= 10; + } - if (places > 2) { - buffer[2] = '0' + number % 10; - number /= 10; - } + if (places > 2) { + buffer[2] = '0' + number % 10; + number /= 10; + } - if (places > 1) { - buffer[1] = '0' + number % 10; - number /= 10; - } + if (places > 1) { + buffer[1] = '0' + number % 10; + number /= 10; + } - buffer[0] = '0' + number % 10; - number /= 10; - print(buffer); + buffer[0] = '0' + number % 10; + number /= 10; + print(buffer); } void OLED::drawSymbol(uint8_t symbolID) { - //draw a symbol to the current cursor location - setFont(2); - drawChar(' ' + symbolID); // space offset is in all fonts, so we pad it here and remove it later - setFont(0); + // draw a symbol to the current cursor location + setFont(2); + drawChar(' ' + symbolID); // space offset is in all fonts, so we pad it here + // and remove it later + setFont(0); } -//Draw an area, but y must be aligned on 0/8 offset +// Draw an area, but y must be aligned on 0/8 offset void OLED::drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, - const uint8_t* ptr) { - // Splat this from x->x+wide in two strides - if (x <= -wide) - return; //cutoffleft - if (x > 96) - return; //cutoff right + const uint8_t* ptr) { + // Splat this from x->x+wide in two strides + if (x <= -wide) return; // cutoffleft + if (x > 96) return; // cutoff right - uint8_t visibleStart = 0; - uint8_t visibleEnd = wide; + uint8_t visibleStart = 0; + uint8_t visibleEnd = wide; - // trimming to draw partials - if (x < 0) { - visibleStart -= x; //subtract negative value == add absolute value - } - if (x + wide > 96) { - visibleEnd = 96 - x; - } + // trimming to draw partials + if (x < 0) { + visibleStart -= x; // subtract negative value == add absolute value + } + if (x + wide > 96) { + visibleEnd = 96 - x; + } - if (y == 0) { - //Splat first line of data - for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { - firstStripPtr[xx + x] = ptr[xx]; - } - } - if (y == 8 || height == 16) { - // Splat the second line - for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { - secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)]; - } - } + if (y == 0) { + // Splat first line of data + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { + firstStripPtr[xx + x] = ptr[xx]; + } + } + if (y == 8 || height == 16) { + // Splat the second line + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { + secondStripPtr[x + xx] = ptr[xx + (height == 16 ? wide : 0)]; + } + } } void OLED::fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, - const uint8_t value) { - // Splat this from x->x+wide in two strides - if (x <= -wide) - return; //cutoffleft - if (x > 96) - return; //cutoff right + const uint8_t value) { + // Splat this from x->x+wide in two strides + if (x <= -wide) return; // cutoffleft + if (x > 96) return; // cutoff right - uint8_t visibleStart = 0; - uint8_t visibleEnd = wide; + uint8_t visibleStart = 0; + uint8_t visibleEnd = wide; - // trimming to draw partials - if (x < 0) { - visibleStart -= x; //subtract negative value == add absolute value - } - if (x + wide > 96) { - visibleEnd = 96 - x; - } + // trimming to draw partials + if (x < 0) { + visibleStart -= x; // subtract negative value == add absolute value + } + if (x + wide > 96) { + visibleEnd = 96 - x; + } - if (y == 0) { - //Splat first line of data - for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { - firstStripPtr[xx + x] = value; - } - } - if (y == 8 || height == 16) { - // Splat the second line - for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { - secondStripPtr[x + xx] = value; - } - } + if (y == 0) { + // Splat first line of data + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { + firstStripPtr[xx + x] = value; + } + } + if (y == 8 || height == 16) { + // Splat the second line + for (uint8_t xx = visibleStart; xx < visibleEnd; xx++) { + secondStripPtr[x + xx] = value; + } + } } void OLED::drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, - bool clear) { - //Draw this in 3 sections - //This is basically a N wide version of vertical line + bool clear) { + // Draw this in 3 sections + // This is basically a N wide version of vertical line - //Step 1 : Draw in the top few pixels that are not /8 aligned - //LSB is at the top of the screen - uint8_t mask = 0xFF; - if (y0) { - mask = mask << (y0 % 8); - for (uint8_t col = x0; col < x1; col++) - if (clear) - firstStripPtr[(y0 / 8) * 96 + col] &= ~mask; - else - firstStripPtr[(y0 / 8) * 96 + col] |= mask; - } - //Next loop down the line the total number of solids - if (y0 / 8 != y1 / 8) - for (uint8_t col = x0; col < x1; col++) - for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) { - //This gives us the row index r - if (clear) - firstStripPtr[(r * 96) + col] = 0; - else - firstStripPtr[(r * 96) + col] = 0xFF; - } + // Step 1 : Draw in the top few pixels that are not /8 aligned + // LSB is at the top of the screen + uint8_t mask = 0xFF; + if (y0) { + mask = mask << (y0 % 8); + for (uint8_t col = x0; col < x1; col++) + if (clear) + firstStripPtr[(y0 / 8) * 96 + col] &= ~mask; + else + firstStripPtr[(y0 / 8) * 96 + col] |= mask; + } + // Next loop down the line the total number of solids + if (y0 / 8 != y1 / 8) + for (uint8_t col = x0; col < x1; col++) + for (uint8_t r = (y0 / 8); r < (y1 / 8); r++) { + // This gives us the row index r + if (clear) + firstStripPtr[(r * 96) + col] = 0; + else + firstStripPtr[(r * 96) + col] = 0xFF; + } - //Finally draw the tail - mask = ~(mask << (y1 % 8)); - for (uint8_t col = x0; col < x1; col++) - if (clear) - firstStripPtr[(y1 / 8) * 96 + col] &= ~mask; - else - firstStripPtr[(y1 / 8) * 96 + col] |= mask; + // Finally draw the tail + mask = ~(mask << (y1 % 8)); + for (uint8_t col = x0; col < x1; col++) + if (clear) + firstStripPtr[(y1 / 8) * 96 + col] &= ~mask; + else + firstStripPtr[(y1 / 8) * 96 + col] |= mask; } void OLED::drawHeatSymbol(uint8_t state) { - //Draw symbol 14 -//Then draw over it botom 5 pixels always stay. 8 pixels above that are the levels - state /= 12; // 0-> 8 range - //Then we want to draw down (16-(5+state) - uint8_t cursor_x_temp = cursor_x; - drawSymbol(14); - drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true); + // Draw symbol 14 + // Then draw over it, the bottom 5 pixels always stay. 8 pixels above that are + // the levels masks the symbol nicely + state /= 12; // 0-> 8 range + // Then we want to draw down (16-(5+state) + uint8_t cursor_x_temp = cursor_x; + drawSymbol(14); + drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true); } diff --git a/workspace/TS100/src/Settings.cpp b/workspace/TS100/src/Settings.cpp index fbafa8f7..c541124c 100644 --- a/workspace/TS100/src/Settings.cpp +++ b/workspace/TS100/src/Settings.cpp @@ -4,61 +4,62 @@ * Created on: 29 Sep 2016 * Author: Ralim * - * This file holds the users settings and saves / restores them to the devices flash + * This file holds the users settings and saves / restores them to the + * devices flash */ #include "Settings.h" #include "Setup.h" -#define FLASH_ADDR (0x8000000|0xFC00)/*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/ +#define FLASH_ADDR \ + (0x8000000 | \ + 0xFC00) /*Flash start OR'ed with the maximum amount of flash - 1024 bytes*/ #include "string.h" volatile systemSettingsType systemSettings; void saveSettings() { - //First we erase the flash - FLASH_EraseInitTypeDef pEraseInit; - pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; - pEraseInit.Banks = FLASH_BANK_1; - pEraseInit.NbPages = 1; - pEraseInit.PageAddress = FLASH_ADDR; - uint32_t failingAddress = 0; - HAL_IWDG_Refresh(&hiwdg); - __HAL_FLASH_CLEAR_FLAG( - FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY); - HAL_FLASH_Unlock(); - HAL_Delay(10); - HAL_IWDG_Refresh(&hiwdg); - HAL_FLASHEx_Erase(&pEraseInit, &failingAddress); - //^ Erase the page of flash (1024 bytes on this stm32) - //erased the chunk - //now we program it - uint16_t *data = (uint16_t*) &systemSettings; - HAL_FLASH_Unlock(); - - for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) { - HAL_IWDG_Refresh(&hiwdg); - HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2), - data[i]); - } - HAL_FLASH_Lock(); + // First we erase the flash + FLASH_EraseInitTypeDef pEraseInit; + pEraseInit.TypeErase = FLASH_TYPEERASE_PAGES; + pEraseInit.Banks = FLASH_BANK_1; + pEraseInit.NbPages = 1; + pEraseInit.PageAddress = FLASH_ADDR; + uint32_t failingAddress = 0; + HAL_IWDG_Refresh(&hiwdg); + __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | + FLASH_FLAG_BSY); + HAL_FLASH_Unlock(); + HAL_Delay(10); + HAL_IWDG_Refresh(&hiwdg); + HAL_FLASHEx_Erase(&pEraseInit, &failingAddress); + //^ Erase the page of flash (1024 bytes on this stm32) + // erased the chunk + // now we program it + uint16_t *data = (uint16_t *)&systemSettings; + HAL_FLASH_Unlock(); + for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) { + HAL_IWDG_Refresh(&hiwdg); + HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, FLASH_ADDR + (i * 2), + data[i]); + } + HAL_FLASH_Lock(); } void restoreSettings() { - //We read the flash - uint16_t *data = (uint16_t*) &systemSettings; - for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) { - data[i] = *((uint16_t*) (FLASH_ADDR + (i * 2))); - } - - //if the version is correct were done - //if not we reset and save - if (systemSettings.version != SETTINGSVERSION) { - //probably not setup - resetSettings(); - } + // We read the flash + uint16_t *data = (uint16_t *)&systemSettings; + for (uint8_t i = 0; i < (sizeof(systemSettingsType) / 2); i++) { + data[i] = *((uint16_t *)(FLASH_ADDR + (i * 2))); + } + // if the version is correct were done + // if not we reset and save + if (systemSettings.version != SETTINGSVERSION) { + // probably not setup + resetSettings(); + } } -//Lookup function for cutoff setting -> X10 voltage +// Lookup function for cutoff setting -> X10 voltage /* * 0=DC * 1=3S @@ -67,36 +68,54 @@ void restoreSettings() { * 4=6S */ uint8_t lookupVoltageLevel(uint8_t level) { - if (level == 0) - return 90; //9V since iron does not function effectively below this - else - return (level * 33) + (33 * 2); + if (level == 0) + return 90; // 9V since iron does not function effectively below this + else + return (level * 33) + (33 * 2); } void resetSettings() { - memset((void*) &systemSettings, 0, sizeof(systemSettingsType)); - systemSettings.SleepTemp = 150; //Temperature the iron sleeps at - default 150.0 C - systemSettings.SleepTime = 6; //How many seconds/minutes we wait until going to sleep - default 1 min - systemSettings.SolderingTemp = 320; //Default soldering temp is 320.0 C - systemSettings.cutoutSetting = 0; //default to no cut-off voltage - systemSettings.version = SETTINGSVERSION;//Store the version number to allow for easier upgrades - systemSettings.detailedSoldering = 0; // Detailed soldering screen - systemSettings.detailedIDLE = 0;// Detailed idle screen (off for first time users) - systemSettings.OrientationMode = 2; //Default to automatic - systemSettings.sensitivity = 7; //Default high sensitivity - systemSettings.voltageDiv = 467; //Default divider from schematic - systemSettings.ShutdownTime = 10;//How many minutes until the unit turns itself off - systemSettings.boostModeEnabled = 1;//Default to safe, with no boost mode - systemSettings.BoostTemp = 420; //default to 400C - systemSettings.autoStartMode = 0; //Auto start off for safety - systemSettings.coolingTempBlink = 0;//Blink the temperature on the cooling screen when its > 50C - systemSettings.temperatureInF = 0; //default to 0 - systemSettings.descriptionScrollSpeed = 0; //default to slow - systemSettings.PID_P = 42; - systemSettings.PID_I = 50; - systemSettings.PID_D = 15; - systemSettings.CalibrationOffset = 2780; // the adc offset - systemSettings.customTipGain = 0; // The tip type is either default or a custom gain - systemSettings.tipType = TS_B2; - saveSettings(); -} + memset((void *)&systemSettings, 0, sizeof(systemSettingsType)); + systemSettings.SleepTemp = + 150; // Temperature the iron sleeps at - default 150.0 C + systemSettings.SleepTime = 6; // How many seconds/minutes we wait until going + // to sleep - default 1 min + systemSettings.SolderingTemp = 320; // Default soldering temp is 320.0 C + systemSettings.cutoutSetting = 0; // default to no cut-off voltage (or 18W for TS80) + systemSettings.version = + SETTINGSVERSION; // Store the version number to allow for easier upgrades + systemSettings.detailedSoldering = 0; // Detailed soldering screen + systemSettings.detailedIDLE = + 0; // Detailed idle screen (off for first time users) + systemSettings.OrientationMode = 2; // Default to automatic + systemSettings.sensitivity = 7; // Default high sensitivity +#ifdef MODEL_TS80 + systemSettings.voltageDiv = 780; // Default divider from schematic +#else + systemSettings.voltageDiv = 467; // Default divider from schematic +#endif + systemSettings.ShutdownTime = + 10; // How many minutes until the unit turns itself off + systemSettings.boostModeEnabled = + 1; // Default to having boost mode on as most people prefer itF + systemSettings.BoostTemp = 420; // default to 400C + systemSettings.autoStartMode = 0; // Auto start off for safety + systemSettings.coolingTempBlink = + 0; // Blink the temperature on the cooling screen when its > 50C + systemSettings.temperatureInF = 0; // default to 0 + systemSettings.descriptionScrollSpeed = 0; // default to slow + systemSettings.PID_P = 42; // PID tuning constants + systemSettings.PID_I = 50; + systemSettings.PID_D = 15; + systemSettings.CalibrationOffset = 2780; // the adc offset + systemSettings.customTipGain = + 0; // The tip type is either default or a custom gain +#ifdef MODEL_TS100 + systemSettings.tipType = TS_B2; // Default to the B2 Tip +#endif +#ifdef MODEL_TS80 + + systemSettings.tipType = TS_B02; // Default to the B2 Tip +#endif + saveSettings(); // Save defaults +} diff --git a/workspace/TS100/src/Setup.c b/workspace/TS100/src/Setup.c index 5df7a5bf..202f98df 100644 --- a/workspace/TS100/src/Setup.c +++ b/workspace/TS100/src/Setup.c @@ -17,9 +17,9 @@ IWDG_HandleTypeDef hiwdg; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; -uint16_t ADCReadings[64]; //room for 32 lots of the pair of readings +uint16_t ADCReadings[64]; // room for 32 lots of the pair of readings -//Functions +// Functions void SystemClock_Config(void); static void MX_ADC1_Init(void); static void MX_I2C1_Init(void); @@ -31,344 +31,340 @@ static void MX_GPIO_Init(void); static void MX_ADC2_Init(void); void Setup_HAL() { - SystemClock_Config(); - MX_GPIO_Init(); - MX_DMA_Init(); - MX_I2C1_Init(); - MX_ADC1_Init(); - MX_ADC2_Init(); - MX_TIM3_Init(); - MX_TIM2_Init(); - MX_IWDG_Init(); - HAL_ADC_Start(&hadc2); - HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*) ADCReadings, 64); //start DMA of normal readings - HAL_ADCEx_InjectedStart(&hadc1); //enable injected readings - HAL_ADCEx_InjectedStart(&hadc2); //enable injected readings - - + SystemClock_Config(); + __HAL_AFIO_REMAP_SWJ_DISABLE(); + MX_GPIO_Init(); + MX_DMA_Init(); + MX_I2C1_Init(); + MX_ADC1_Init(); + MX_ADC2_Init(); + MX_TIM3_Init(); + MX_TIM2_Init(); + MX_IWDG_Init(); + HAL_ADC_Start(&hadc2); + HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*)ADCReadings, + 64); // start DMA of normal readings + HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings + HAL_ADCEx_InjectedStart(&hadc2); // enable injected readings } -//channel 0 -> temperature sensor, 1-> VIN +// channel 0 -> temperature sensor, 1-> VIN uint16_t getADC(uint8_t channel) { - uint32_t sum = 0; - for (uint8_t i = 0; i < 32; i++) - sum += ADCReadings[channel + (i * 2)]; - return sum >> 2; + uint32_t sum = 0; + for (uint8_t i = 0; i < 32; i++) sum += ADCReadings[channel + (i * 2)]; + return sum >> 2; } /** System Clock Configuration */ void SystemClock_Config(void) { + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_PeriphCLKInitTypeDef PeriphClkInit; - RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_ClkInitTypeDef RCC_ClkInitStruct; - RCC_PeriphCLKInitTypeDef PeriphClkInit; + /**Initializes the CPU, AHB and APB busses clocks + */ + RCC_OscInitStruct.OscillatorType = + RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = 16; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; // 64MHz + HAL_RCC_OscConfig(&RCC_OscInitStruct); - /**Initializes the CPU, AHB and APB busses clocks - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI - | RCC_OSCILLATORTYPE_LSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = 16; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16; //64MHz - HAL_RCC_OscConfig(&RCC_OscInitStruct); + /**Initializes the CPU, AHB and APB busses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | + RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM + // 2,3,4,5,6,7,12,13,14 + RCC_ClkInitStruct.APB2CLKDivider = + RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc - /**Initializes the CPU, AHB and APB busses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK - | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; //TIM 2,3,4,5,6,7,12,13,14 - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; //64 mhz to some peripherals and adc + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); - HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; + PeriphClkInit.AdcClockSelection = + RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options + HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; - PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; //6 or 8 are the only non overclocked options - HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); + /**Configure the Systick interrupt time + */ + HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); - /**Configure the Systick interrupt time - */ - HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000); + /**Configure the Systick + */ + HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); - /**Configure the Systick - */ - HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); - - /* SysTick_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0); + /* SysTick_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0); } /* ADC1 init function */ static void MX_ADC1_Init(void) { - ADC_MultiModeTypeDef multimode; + ADC_MultiModeTypeDef multimode; - ADC_ChannelConfTypeDef sConfig; - ADC_InjectionConfTypeDef sConfigInjected; - /**Common config - */ - hadc1.Instance = ADC1; - hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; - hadc1.Init.ContinuousConvMode = ENABLE; - hadc1.Init.DiscontinuousConvMode = DISABLE; - hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc1.Init.NbrOfConversion = 2; - HAL_ADC_Init(&hadc1); + ADC_ChannelConfTypeDef sConfig; + ADC_InjectionConfTypeDef sConfigInjected; + /**Common config + */ + hadc1.Instance = ADC1; + hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; + hadc1.Init.ContinuousConvMode = ENABLE; + hadc1.Init.DiscontinuousConvMode = DISABLE; + hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc1.Init.NbrOfConversion = 2; + HAL_ADC_Init(&hadc1); - /**Configure the ADC multi-mode - */ - multimode.Mode = ADC_DUALMODE_REGSIMULT_INJECSIMULT; - HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode); + /**Configure the ADC multi-mode + */ + multimode.Mode = ADC_DUALMODE_REGSIMULT_INJECSIMULT; + HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode); - /**Configure Regular Channel - */ - sConfig.Channel = ADC_CHANNEL_7; - sConfig.Rank = 1; - sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; - HAL_ADC_ConfigChannel(&hadc1, &sConfig); + /**Configure Regular Channel + */ + sConfig.Channel = TMP36_ADC1_CHANNEL; + sConfig.Rank = 1; + sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; + HAL_ADC_ConfigChannel(&hadc1, &sConfig); - /**Configure Regular Channel - */ - sConfig.Channel = ADC_CHANNEL_9; - sConfig.Rank = 2; - HAL_ADC_ConfigChannel(&hadc1, &sConfig); + /**Configure Regular Channel + */ + sConfig.Channel = VIN_ADC1_CHANNEL; + sConfig.Rank = 2; + HAL_ADC_ConfigChannel(&hadc1, &sConfig); - /**Configure Injected Channel - */ - //F in = 10.66 MHz - /* - * Injected time is 1 delay clock + (12 adc cycles*4)+4*sampletime =~217 clocks = 0.2ms - * Charge time is 0.016 uS ideally - * So Sampling time must be >= 0.016uS - * 1/10.66MHz is 0.09uS, so 1 CLK is *should* be enough - * */ - sConfigInjected.InjectedChannel = ADC_CHANNEL_8; - sConfigInjected.InjectedRank = 1; - sConfigInjected.InjectedNbrOfConversion = 4; - sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5; - sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1; - sConfigInjected.AutoInjectedConv = DISABLE; - sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; - sConfigInjected.InjectedOffset = 0; + /**Configure Injected Channel + */ + // F in = 10.66 MHz + /* + * Injected time is 1 delay clock + (12 adc cycles*4)+4*sampletime =~217 + * clocks = 0.2ms Charge time is 0.016 uS ideally So Sampling time must be >= + * 0.016uS 1/10.66MHz is 0.09uS, so 1 CLK is *should* be enough + * */ + sConfigInjected.InjectedChannel = TIP_TEMP_ADC1_CHANNEL; + sConfigInjected.InjectedRank = 1; + sConfigInjected.InjectedNbrOfConversion = 4; + sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5; + sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1; + sConfigInjected.AutoInjectedConv = DISABLE; + sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; + sConfigInjected.InjectedOffset = 0; - HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); + HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); - sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5; - sConfigInjected.InjectedRank = 2; - HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); - sConfigInjected.InjectedRank = 3; - HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); - sConfigInjected.InjectedRank = 4; - HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); - SET_BIT(hadc1.Instance->CR1, ( ADC_CR1_JEOCIE )); //Enable end of injected conv irq - // Run ADC internal calibration - while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK) - ; + sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5; + sConfigInjected.InjectedRank = 2; + HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); + sConfigInjected.InjectedRank = 3; + HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); + sConfigInjected.InjectedRank = 4; + HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected); + SET_BIT(hadc1.Instance->CR1, + (ADC_CR1_JEOCIE)); // Enable end of injected conv irq + // Run ADC internal calibration + while (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK) + ; } /* ADC2 init function */ static void MX_ADC2_Init(void) { + ADC_ChannelConfTypeDef sConfig; + ADC_InjectionConfTypeDef sConfigInjected; - ADC_ChannelConfTypeDef sConfig; - ADC_InjectionConfTypeDef sConfigInjected; + /**Common config + */ + hadc2.Instance = ADC2; + hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE; + hadc2.Init.ContinuousConvMode = ENABLE; + hadc2.Init.DiscontinuousConvMode = DISABLE; + hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START; + hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT; + hadc2.Init.NbrOfConversion = 2; + HAL_ADC_Init(&hadc2); - /**Common config - */ - hadc2.Instance = ADC2; - hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE; - hadc2.Init.ContinuousConvMode = ENABLE; - hadc2.Init.DiscontinuousConvMode = DISABLE; - hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START; - hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT; - hadc2.Init.NbrOfConversion = 2; - HAL_ADC_Init(&hadc2); + /**Configure Regular Channel + */ + sConfig.Channel = TIP_TEMP_ADC2_CHANNEL; + sConfig.Rank = ADC_REGULAR_RANK_1; + sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; + HAL_ADC_ConfigChannel(&hadc2, &sConfig); + sConfig.Channel = VIN_ADC2_CHANNEL; + sConfig.Rank = ADC_REGULAR_RANK_2; + sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; + HAL_ADC_ConfigChannel(&hadc2, &sConfig); - /**Configure Regular Channel - */ - sConfig.Channel = ADC_CHANNEL_8; - sConfig.Rank = ADC_REGULAR_RANK_1; - sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; - HAL_ADC_ConfigChannel(&hadc2, &sConfig); - sConfig.Channel = ADC_CHANNEL_8; - sConfig.Rank = ADC_REGULAR_RANK_2; - sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; - HAL_ADC_ConfigChannel(&hadc2, &sConfig); + /**Configure Injected Channel + */ + sConfigInjected.InjectedChannel = TIP_TEMP_ADC2_CHANNEL; + sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1; + sConfigInjected.InjectedNbrOfConversion = 4; + sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5; + sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1; + sConfigInjected.AutoInjectedConv = DISABLE; + sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; + sConfigInjected.InjectedOffset = 0; + HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); + sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5; - /**Configure Injected Channel - */ - sConfigInjected.InjectedChannel = ADC_CHANNEL_8; - sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1; - sConfigInjected.InjectedNbrOfConversion = 4; - sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_7CYCLES_5; - sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T2_CC1; - sConfigInjected.AutoInjectedConv = DISABLE; - sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; - sConfigInjected.InjectedOffset = 0; - HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); - sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_1CYCLE_5; - - sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2; - HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); - sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3; - HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); - sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4; - HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); - - // Run ADC internal calibration - while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK) - ; + sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2; + HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); + sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3; + HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); + sConfigInjected.InjectedRank = ADC_INJECTED_RANK_4; + HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); + // Run ADC internal calibration + while (HAL_ADCEx_Calibration_Start(&hadc2) != HAL_OK) + ; } /* I2C1 init function */ static void MX_I2C1_Init(void) { - - hi2c1.Instance = I2C1; - hi2c1.Init.ClockSpeed = 100000; // OLED doesnt handle >100k when its asleep (off). - hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; - hi2c1.Init.OwnAddress1 = 0; - hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; - hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; - hi2c1.Init.OwnAddress2 = 0; - hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; - hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; - HAL_I2C_Init(&hi2c1); - + hi2c1.Instance = I2C1; + hi2c1.Init.ClockSpeed = + 100000; // OLED doesnt handle >100k when its asleep (off). + hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2; + hi2c1.Init.OwnAddress1 = 0; + hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + hi2c1.Init.OwnAddress2 = 0; + hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + HAL_I2C_Init(&hi2c1); } /* IWDG init function */ static void MX_IWDG_Init(void) { - - hiwdg.Instance = IWDG; - hiwdg.Init.Prescaler = IWDG_PRESCALER_256; - hiwdg.Init.Reload = 100; - HAL_IWDG_Init(&hiwdg); - + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_256; + hiwdg.Init.Reload = 100; + HAL_IWDG_Init(&hiwdg); } /* TIM3 init function */ static void MX_TIM3_Init(void) { + TIM_ClockConfigTypeDef sClockSourceConfig; + TIM_MasterConfigTypeDef sMasterConfig; + TIM_OC_InitTypeDef sConfigOC; - TIM_ClockConfigTypeDef sClockSourceConfig; - TIM_MasterConfigTypeDef sMasterConfig; - TIM_OC_InitTypeDef sConfigOC; + htim3.Instance = TIM3; + htim3.Init.Prescaler = 2; + htim3.Init.CounterMode = TIM_COUNTERMODE_UP; + htim3.Init.Period = 100; // 10 Khz PWM freq + htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before div + htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + HAL_TIM_Base_Init(&htim3); - htim3.Instance = TIM3; - htim3.Init.Prescaler = 2; - htim3.Init.CounterMode = TIM_COUNTERMODE_UP; - htim3.Init.Period = 100; //10 Khz PWM freq - htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; //4mhz before div - htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - HAL_TIM_Base_Init(&htim3); + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig); - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig); + HAL_TIM_PWM_Init(&htim3); - HAL_TIM_PWM_Init(&htim3); + HAL_TIM_OC_Init(&htim3); - HAL_TIM_OC_Init(&htim3); + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig); - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig); + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 50; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; + HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL); - sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 50; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; - HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1); - - GPIO_InitTypeDef GPIO_InitStruct; - - /**TIM3 GPIO Configuration - PB4 ------> TIM3_CH1 - */ - GPIO_InitStruct.Pin = PWM_Out_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct); - - __HAL_AFIO_REMAP_TIM3_PARTIAL() - ; - HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); + GPIO_InitTypeDef GPIO_InitStruct; + /**TIM3 GPIO Configuration + PWM_Out_Pin ------> TIM3_CH1 + */ + GPIO_InitStruct.Pin = PWM_Out_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct); +#ifdef MODEL_TS100 + // Remap TIM3_CH1 to be on pB4 + __HAL_AFIO_REMAP_TIM3_PARTIAL(); +#else + // No re-map required +#endif + HAL_TIM_PWM_Start(&htim3, PWM_Out_CHANNEL); } /* TIM3 init function */ static void MX_TIM2_Init(void) { - /* - * We use the channel 1 to trigger the ADC at end of PWM period - * And we use the channel 4 as the PWM modulation source using Interrupts - * */ - TIM_ClockConfigTypeDef sClockSourceConfig; - TIM_MasterConfigTypeDef sMasterConfig; - TIM_OC_InitTypeDef sConfigOC; + /* + * We use the channel 1 to trigger the ADC at end of PWM period + * And we use the channel 4 as the PWM modulation source using Interrupts + * */ + TIM_ClockConfigTypeDef sClockSourceConfig; + TIM_MasterConfigTypeDef sMasterConfig; + TIM_OC_InitTypeDef sConfigOC; - //Timer 2 is fairly slow as its being used to run the PWM and trigger the ADC in the PWM off time. - htim2.Instance = TIM2; - htim2.Init.Prescaler = 2000; // pwm out is 10k, we want to run our PWM at around 100hz - htim2.Init.CounterMode = TIM_COUNTERMODE_UP; - htim2.Init.Period = 122; - htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; //4mhz before divide - htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; - HAL_TIM_Base_Init(&htim2); + // Timer 2 is fairly slow as its being used to run the PWM and trigger the ADC + // in the PWM off time. + htim2.Instance = TIM2; + htim2.Init.Prescaler = + 2000; // pwm out is 10k, we want to run our PWM at around 100hz + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = 122; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV4; // 4mhz before divide + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + HAL_TIM_Base_Init(&htim2); - sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; - HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig); + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig); - HAL_TIM_PWM_Init(&htim2); - HAL_TIM_OC_Init(&htim2); + HAL_TIM_PWM_Init(&htim2); + HAL_TIM_OC_Init(&htim2); - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig); + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig); - sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 118; - /* - * It takes 4 milliseconds for output to be stable after PWM turns off. - * Assume ADC samples in 0.5ms - * We need to set this to 100% + 5.5ms - * */ - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; - HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1); + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 118; + /* + * It takes 4 milliseconds for output to be stable after PWM turns off. + * Assume ADC samples in 0.5ms + * We need to set this to 100% + 5.5ms + * */ + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; + HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1); - sConfigOC.OCMode = TIM_OCMODE_PWM1; - sConfigOC.Pulse = 0; - sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; - sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; - HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4); - - HAL_TIM_Base_Start_IT(&htim2); - HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); - HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_4); - HAL_NVIC_EnableIRQ(TIM2_IRQn); + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCFastMode = TIM_OCFAST_ENABLE; + HAL_TIM_OC_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4); + HAL_TIM_Base_Start_IT(&htim2); + HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); + HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_4); + HAL_NVIC_EnableIRQ(TIM2_IRQn); } /** * Enable DMA controller clock */ static void MX_DMA_Init(void) { - /* DMA controller clock enable */ - __HAL_RCC_DMA1_CLK_ENABLE() - ; - - /* DMA interrupt init */ - /* DMA1_Channel1_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 15, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); - /* DMA1_Channel6_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 15, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); - /* DMA1_Channel7_IRQn interrupt configuration */ - HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 15, 0); - HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); + /* DMA controller clock enable */ + __HAL_RCC_DMA1_CLK_ENABLE(); + /* DMA interrupt init */ + /* DMA1_Channel1_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); + /* DMA1_Channel6_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn); + /* DMA1_Channel7_IRQn interrupt configuration */ + HAL_NVIC_SetPriority(DMA1_Channel7_IRQn, 15, 0); + HAL_NVIC_EnableIRQ(DMA1_Channel7_IRQn); } /** Configure pins as @@ -382,71 +378,73 @@ static void MX_DMA_Init(void) { PB1 ------> ADCx_IN9 */ static void MX_GPIO_Init(void) { + GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitTypeDef GPIO_InitStruct; + /* GPIO Ports Clock Enable */ + __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); - /* GPIO Ports Clock Enable */ - __HAL_RCC_GPIOD_CLK_ENABLE() - ; - __HAL_RCC_GPIOA_CLK_ENABLE() - ; - __HAL_RCC_GPIOB_CLK_ENABLE() - ; + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET); + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + /*Configure GPIO pins : PD0 PD1 */ + GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + /*Configure peripheral I/O remapping */ + __HAL_AFIO_REMAP_PD01_ENABLE(); + //^ remap XTAL so that pins can be analog (all input buffers off). + // reduces power consumption - /*Configure GPIO pin Output Level */ - HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET); - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - /*Configure GPIO pins : PD0 PD1 */ - GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); + /* + * Configure All pins as analog by default + */ + GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | + GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | + GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | +#ifdef MODEL_TS100 + GPIO_PIN_3 | +#endif + GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | + GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | + GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - /*Configure GPIO pins : PA0 PA1 PA2 PA3 - PA4 PA5 PA10 PA15 */ - GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 - | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 - | GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +#ifdef MODEL_TS100 + /* Pull USB lines low to disable, pull down debug too*/ + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET); +#else + /* TS80 */ + /* Leave USB lines open circuit*/ - //Set PA 11 and PA 12 to GND to stop usb detection, 13/14 re-rused for debug - GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_13, GPIO_PIN_RESET); - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_14, GPIO_PIN_RESET); +#endif - /*Configure GPIO pins : KEY_B_Pin KEY_A_Pin */ - GPIO_InitStruct.Pin = KEY_B_Pin | KEY_A_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + /*Configure GPIO pins : KEY_B_Pin KEY_A_Pin */ + GPIO_InitStruct.Pin = KEY_B_Pin | KEY_A_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(KEY_B_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pins : TIP_TEMP_Pin VIN_Pin PB2 */ - GPIO_InitStruct.Pin = TIP_TEMP_Pin | VIN_Pin | GPIO_PIN_2; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure GPIO pin : OLED_RESET_Pin */ - GPIO_InitStruct.Pin = OLED_RESET_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(OLED_RESET_GPIO_Port, &GPIO_InitStruct); - HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET); - - /* Configure GPIO pins : INT_Orientation_Pin INT_Movement_Pin */ - /* Not used anymore*/ - GPIO_InitStruct.Pin = INT_Orientation_Pin | INT_Movement_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - GPIO_InitStruct.Pull = GPIO_PULLUP; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - - /*Configure peripheral I/O remapping */ - __HAL_AFIO_REMAP_PD01_ENABLE(); - //^ remap XTAL so that pins can be analog (all input buffers off). - // reduces power consumption + /*Configure GPIO pin : OLED_RESET_Pin */ + GPIO_InitStruct.Pin = OLED_RESET_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(OLED_RESET_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET); + // Pull down LCD reset + HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET); + HAL_Delay(10); + HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET); } diff --git a/workspace/TS100/src/Translation.cpp b/workspace/TS100/src/Translation.cpp index ac18ed59..f39785b8 100644 --- a/workspace/TS100/src/Translation.cpp +++ b/workspace/TS100/src/Translation.cpp @@ -1,4 +1,5 @@ -// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT EDIT. +// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT +// EDIT. #include "Translation.h" #ifndef LANG @@ -29,6 +30,7 @@ const char* SettingsDescriptions[] = { /* TipModel */ "Tip Model selection", /* SimpleCalibrationMode */ "Simple Calibration using Hot water", /* AdvancedCalibrationMode */ "Advanced calibration using thermocouple on the tip", + /* Power Input */ "The power rating of the power adapter", }; const char* SettingsCalibrationDone = "Calibration done!"; @@ -81,17 +83,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldering\nSettings", - /* PowerSavingMenu */ "Sleep\nModes", - /* UIMenu */ "User\nInterface", - /* AdvancedMenu */ "Advanced\nOptions", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldering settings", - /* PowerSavingMenu */ "Power saving settings", - /* UIMenu */ "User interface settings", - /* AdvancedMenu */ "Advanced options", + /* SolderingMenu */ "Soldering\nSettings", + /* PowerSavingMenu */ "Sleep\nModes", + /* UIMenu */ "User\nInterface", + /* AdvancedMenu */ "Advanced\nOptions", }; #endif @@ -172,17 +167,17 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Поялник\nНастройки", - /* PowerSavingMenu */ "Режими\nНастройки", - /* UIMenu */ "Интерфейс\nНастройки", - /* AdvancedMenu */ "Разширени\nНастройки", + /* SolderingMenu */ "Поялник\nНастройки", + /* PowerSavingMenu */ "Режими\nНастройки", + /* UIMenu */ "Интерфейс\nНастройки", + /* AdvancedMenu */ "Разширени\nНастройки", }; const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Настройки на поялника", - /* PowerSavingMenu */ "Настройки енергоспестяване", - /* UIMenu */ "Настройки на интерфейса", - /* AdvancedMenu */ "Допълнителни настройки", + /* SolderingMenu */ "Настройки на поялника", + /* PowerSavingMenu */ "Настройки енергоспестяване", + /* UIMenu */ "Настройки на интерфейса", + /* AdvancedMenu */ "Допълнителни настройки", }; #endif @@ -263,17 +258,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Pájecí\nnastavení", - /* PowerSavingMenu */ "Režim\nspánku", - /* UIMenu */ "Uživatelské\nrozhraní", - /* AdvancedMenu */ "Pokročilé\nvolby", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Nastavení pájení (boost, auto start...)", - /* PowerSavingMenu */ "Nastavení režimu spánku, automatického vypnutí...", - /* UIMenu */ "Nastavení uživatelského rozhraní.", - /* AdvancedMenu */ "Pokročilé volby (detailní obrazovky, kalibrace, tovární nastavení...)", + /* SolderingMenu */ "Pájecí\nnastavení", + /* PowerSavingMenu */ "Režim\nspánku", + /* UIMenu */ "Uživatelské\nrozhraní", + /* AdvancedMenu */ "Pokročilé\nvolby", }; #endif @@ -354,17 +342,17 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Löt-\neinstellungen", - /* PowerSavingMenu */ "Schlaf-\nmodus", - /* UIMenu */ "Menü-\neinstellungen", - /* AdvancedMenu */ "Erweiterte\nEinstellungen", + /* SolderingMenu */ "Löt-\neinstellungen", + /* PowerSavingMenu */ "Schlaf-\nmodus", + /* UIMenu */ "Menü-\neinstellungen", + /* AdvancedMenu */ "Erweiterte\nEinstellungen", }; const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Löteinstellungen", - /* PowerSavingMenu */ "Energiespareinstellungen", - /* UIMenu */ "Menüeinstellungen", - /* AdvancedMenu */ "Erweiterte Einstellungen", + /* SolderingMenu */ "Löteinstellungen", + /* PowerSavingMenu */ "Energiespareinstellungen", + /* UIMenu */ "Menüeinstellungen", + /* AdvancedMenu */ "Erweiterte Einstellungen", }; #endif @@ -445,17 +433,17 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldering\nSettings", - /* PowerSavingMenu */ "Sleep\nModes", - /* UIMenu */ "User\nInterface", - /* AdvancedMenu */ "Advanced\nOptions", + /* SolderingMenu */ "Soldering\nSettings", + /* PowerSavingMenu */ "Sleep\nModes", + /* UIMenu */ "User\nInterface", + /* AdvancedMenu */ "Advanced\nOptions", }; const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldering settings", - /* PowerSavingMenu */ "Power Saving Settings", - /* UIMenu */ "User Interface settings", - /* AdvancedMenu */ "Advanced options", + /* SolderingMenu */ "Soldering settings", + /* PowerSavingMenu */ "Power Saving Settings", + /* UIMenu */ "User Interface settings", + /* AdvancedMenu */ "Advanced options", }; #endif @@ -536,17 +524,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Opciones de\nSoldadura", - /* PowerSavingMenu */ "Modos de\nReposo", - /* UIMenu */ "Interfaz\nde Usuario", - /* AdvancedMenu */ "Opciones\nAvanzadas", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Opciones de Soldadura", - /* PowerSavingMenu */ "Opciones de ahorro energético", - /* UIMenu */ "Opciones de interfaz de usuario", - /* AdvancedMenu */ "Opciones avanzadas", + /* SolderingMenu */ "Opciones de\nSoldadura", + /* PowerSavingMenu */ "Modos de\nReposo", + /* UIMenu */ "Interfaz\nde Usuario", + /* AdvancedMenu */ "Opciones\nAvanzadas", }; #endif @@ -627,17 +608,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Juotos-\nasetukset", - /* PowerSavingMenu */ "Lepotilan\nasetukset", - /* UIMenu */ "Käyttö-\nliittymä", - /* AdvancedMenu */ "Lisä-\nasetukset", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Juotosasetukset", - /* PowerSavingMenu */ "Virransäästöasetukset", - /* UIMenu */ "Käyttöliittymän asetukset", - /* AdvancedMenu */ "Lisäasetukset", + /* SolderingMenu */ "Juotos-\nasetukset", + /* PowerSavingMenu */ "Lepotilan\nasetukset", + /* UIMenu */ "Käyttö-\nliittymä", + /* AdvancedMenu */ "Lisä-\nasetukset", }; #endif @@ -718,17 +692,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soudure\nParamètres", - /* PowerSavingMenu */ "Mode\nVeille", - /* UIMenu */ "Interface\nUtilisateur", - /* AdvancedMenu */ "Options\nAdvanced", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Paramètres de soudage", - /* PowerSavingMenu */ "Paramètres d'économie d'énergie", - /* UIMenu */ "Paramètres de l'interface utilisateur", - /* AdvancedMenu */ "Options avancées", + /* SolderingMenu */ "Soudure\nParamètres", + /* PowerSavingMenu */ "Mode\nVeille", + /* UIMenu */ "Interface\nUtilisateur", + /* AdvancedMenu */ "Options\nAdvanced", }; #endif @@ -809,17 +776,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Postavke\nlemljenja", - /* PowerSavingMenu */ "Ušteda\nenergije", - /* UIMenu */ "Korisničko\nsučelje", - /* AdvancedMenu */ "Napredne\nopcije", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Postavke pri lemljenju", - /* PowerSavingMenu */ "Postavke spavanja i štednje energije", - /* UIMenu */ "Postavke korisničkog sučelja", - /* AdvancedMenu */ "Upravljanje naprednim opcijama", + /* SolderingMenu */ "Postavke\nlemljenja", + /* PowerSavingMenu */ "Ušteda\nenergije", + /* UIMenu */ "Korisničko\nsučelje", + /* AdvancedMenu */ "Napredne\nopcije", }; #endif @@ -900,17 +860,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Forrasztás\nBeállítások", - /* PowerSavingMenu */ "Alvás\nMódok", - /* UIMenu */ "Felhasználó\nfelület", - /* AdvancedMenu */ "Speciális\nbeállítások", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Forrasztási beállítások", - /* PowerSavingMenu */ "Energiatakarékossági beállítások", - /* UIMenu */ "Felhasználói felület beállításai", - /* AdvancedMenu */ "Speciális beállítások", + /* SolderingMenu */ "Forrasztás\nBeállítások", + /* PowerSavingMenu */ "Alvás\nMódok", + /* UIMenu */ "Felhasználó\nfelület", + /* AdvancedMenu */ "Speciális\nbeállítások", }; #endif @@ -1082,17 +1035,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Litavimo\nnustatymai", - /* PowerSavingMenu */ "Miego\nrežimai", - /* UIMenu */ "Naudotojo\nsąsaja", - /* AdvancedMenu */ "Išplėstin.\nnustatymai", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Litavimo nustatymai", - /* PowerSavingMenu */ "Energijos vartojimo nustatymai", - /* UIMenu */ "Naudotojo sąsajos nustatymai", - /* AdvancedMenu */ "Išplėstiniai nustatymai", + /* SolderingMenu */ "Litavimo\nnustatymai", + /* PowerSavingMenu */ "Miego\nrežimai", + /* UIMenu */ "Naudotojo\nsąsaja", + /* AdvancedMenu */ "Išplėstin.\nnustatymai", }; #endif @@ -1173,17 +1119,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldeer\nInstellingen", - /* PowerSavingMenu */ "Slaap\nModes", - /* UIMenu */ "Gebruikers-\nInterface", - /* AdvancedMenu */ "geavanceerde\nInstellingen", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldeerinstellingen", - /* PowerSavingMenu */ "Batterijbesparingsinstellingen", - /* UIMenu */ "Gebruikersinterface Instellingen", - /* AdvancedMenu */ "geavanceerde Instellingen", + /* SolderingMenu */ "Soldeer\nInstellingen", + /* PowerSavingMenu */ "Slaap\nModes", + /* UIMenu */ "Gebruikers-\nInterface", + /* AdvancedMenu */ "geavanceerde\nInstellingen", }; #endif @@ -1264,17 +1203,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Lodde-\ninnst.", - /* PowerSavingMenu */ "Dvale-\ninnst.", - /* UIMenu */ "Bruker-\ngrensesn.", - /* AdvancedMenu */ "Avanserte\nvalg", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Loddeinnstillinger", - /* PowerSavingMenu */ "Dvaleinnstillinger", - /* UIMenu */ "Brukergrensesnitt-innstillinger", - /* AdvancedMenu */ "Avanserte valg", + /* SolderingMenu */ "Lodde-\ninnst.", + /* PowerSavingMenu */ "Dvale-\ninnst.", + /* UIMenu */ "Bruker-\ngrensesn.", + /* AdvancedMenu */ "Avanserte\nvalg", }; #endif @@ -1355,17 +1287,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldering\nSettings", - /* PowerSavingMenu */ "Sleep\nModes", - /* UIMenu */ "User\nInterface", - /* AdvancedMenu */ "Advanced\nOptions", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldering settings", - /* PowerSavingMenu */ "Power Saving Settings", - /* UIMenu */ "User Interface settings", - /* AdvancedMenu */ "Advanced options", + /* SolderingMenu */ "Soldering\nSettings", + /* PowerSavingMenu */ "Sleep\nModes", + /* UIMenu */ "User\nInterface", + /* AdvancedMenu */ "Advanced\nOptions", }; #endif @@ -1446,17 +1371,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Configurações\nSolda", - /* PowerSavingMenu */ "Modos\nRepouso", - /* UIMenu */ "Interface\nUsuário", - /* AdvancedMenu */ "Menu\nAvançado", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Configurações de soldagem", - /* PowerSavingMenu */ "Configurações de economia de energia", - /* UIMenu */ "Configurações da interface do usuário", - /* AdvancedMenu */ "Opções avançadas", + /* SolderingMenu */ "Configurações\nSolda", + /* PowerSavingMenu */ "Modos\nRepouso", + /* UIMenu */ "Interface\nUsuário", + /* AdvancedMenu */ "Menu\nAvançado", }; #endif @@ -1537,17 +1455,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Параметры\nпайки", - /* PowerSavingMenu */ "Режим\nсна", - /* UIMenu */ "Пользовател\nинтерфейс", - /* AdvancedMenu */ "Дополнител.\nпараметры", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Параметры пайки", - /* PowerSavingMenu */ "Параметры экономии энергии", - /* UIMenu */ "Параметры пользовательского интерфейса", - /* AdvancedMenu */ "Дополнительные параметры", + /* SolderingMenu */ "Параметры\nпайки", + /* PowerSavingMenu */ "Режим\nсна", + /* UIMenu */ "Пользовател\nинтерфейс", + /* AdvancedMenu */ "Дополнител.\nпараметры", }; #endif @@ -1628,17 +1539,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldering\nSettings", - /* PowerSavingMenu */ "Sleep\nModes", - /* UIMenu */ "User\nInterface", - /* AdvancedMenu */ "Advanced\nOptions", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldering settings", - /* PowerSavingMenu */ "Power Saving Settings", - /* UIMenu */ "User Interface settings", - /* AdvancedMenu */ "Advanced options", + /* SolderingMenu */ "Soldering\nSettings", + /* PowerSavingMenu */ "Sleep\nModes", + /* UIMenu */ "User\nInterface", + /* AdvancedMenu */ "Advanced\nOptions", }; #endif @@ -1719,17 +1623,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Postavke\nlemljenja", - /* PowerSavingMenu */ "Ušteda\nenergije", - /* UIMenu */ "Korisničke\nopcije", - /* AdvancedMenu */ "Napredne\nopcije", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Postavke pri lemljenju", - /* PowerSavingMenu */ "Postavke spavanja i štednje energije", - /* UIMenu */ "Postavke korisničkih opcija", - /* AdvancedMenu */ "Upravljanje naprednim opcijama", + /* SolderingMenu */ "Postavke\nlemljenja", + /* PowerSavingMenu */ "Ušteda\nenergije", + /* UIMenu */ "Korisničke\nopcije", + /* AdvancedMenu */ "Napredne\nopcije", }; #endif @@ -1810,17 +1707,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Lödnings-\ninställningar", - /* PowerSavingMenu */ "Vilo-\nlägen", - /* UIMenu */ "Användar-\ngränssnitt", - /* AdvancedMenu */ "Avancerade\nalternativ", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Lödningsinställningar", - /* PowerSavingMenu */ "Viloläges-inställningar", - /* UIMenu */ "Användargränssnitts-inställningar", - /* AdvancedMenu */ "Avancerade alternativ", + /* SolderingMenu */ "Lödnings-\ninställningar", + /* PowerSavingMenu */ "Vilo-\nlägen", + /* UIMenu */ "Användar-\ngränssnitt", + /* AdvancedMenu */ "Avancerade\nalternativ", }; #endif @@ -1901,17 +1791,10 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Soldering\nSettings", - /* PowerSavingMenu */ "Sleep\nModes", - /* UIMenu */ "User\nInterface", - /* AdvancedMenu */ "Advanced\nOptions", -}; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Soldering settings", - /* PowerSavingMenu */ "Power Saving Settings", - /* UIMenu */ "User Interface settings", - /* AdvancedMenu */ "Advanced options", + /* SolderingMenu */ "Soldering\nSettings", + /* PowerSavingMenu */ "Sleep\nModes", + /* UIMenu */ "User\nInterface", + /* AdvancedMenu */ "Advanced\nOptions", }; #endif @@ -1992,17 +1875,9 @@ const char* SettingsShortNames[][2] = { }; const char* SettingsMenuEntries[4] = { - /* SolderingMenu */ "Пайка\n", - /* PowerSavingMenu */ "Сон\n", - /* UIMenu */ "Інтерфейс\n", - /* AdvancedMenu */ "Інші\n", + /* SolderingMenu */ "Пайка\n", + /* PowerSavingMenu */ "Сон\n", + /* UIMenu */ "Інтерфейс\n", + /* AdvancedMenu */ "Інші\n", }; - -const char* SettingsMenuEntriesDescriptions[4] = { - /* SolderingMenu */ "Налаштування для режиму пайки. Діють при включеному жалі.", - /* PowerSavingMenu */ "Налаштування при бездіяльності. Корисно що б не обпектися і з часом не спалити житло.", - /* UIMenu */ "Користувальницький інтерфейс.", - /* AdvancedMenu */ "Розширені налаштування. Додаткові зручності.", -}; - #endif diff --git a/workspace/TS100/src/gui.cpp b/workspace/TS100/src/gui.cpp index b78964f6..256f1b57 100644 --- a/workspace/TS100/src/gui.cpp +++ b/workspace/TS100/src/gui.cpp @@ -6,15 +6,21 @@ */ #include "gui.hpp" -#include "main.hpp" -#include "cmsis_os.h" #include "Translation.h" +#include "cmsis_os.h" +#include "main.hpp" #include "string.h" extern uint32_t lastButtonTime; void gui_Menu(const menuitem* menu); +#ifdef MODEL_TS100 static void settings_setInputVRange(void); static void settings_displayInputVRange(void); +#else +static void settings_setInputPRange(void); +static void settings_displayInputPRange(void); + +#endif static void settings_setSleepTemp(void); static void settings_displaySleepTemp(void); static void settings_setSleepTime(void); @@ -51,13 +57,13 @@ static void settings_displayCalibrate(void); static void settings_setCalibrateVIN(void); static void settings_displayCalibrateVIN(void); -//Calibration Menu -static void calibration_displaySimpleCal(void); // Hot water cal +// Calibration Menu +static void calibration_displaySimpleCal(void); // Hot water cal static void calibration_enterSimpleCal(void); -static void calibration_displayAdvancedCal(void); // two point cal +static void calibration_displayAdvancedCal(void); // two point cal static void calibration_enterAdvancedCal(void); -//Menu functions +// Menu functions static void settings_displaySolderingMenu(void); static void settings_enterSolderingMenu(void); static void settings_displayPowerMenu(void); @@ -97,7 +103,7 @@ static void settings_enterAdvancedMenu(void); * Reset Settings * */ -const menuitem rootSettingsMenu[] { +const menuitem rootSettingsMenu[]{ /* * Power Source * Soldering Menu @@ -106,122 +112,143 @@ const menuitem rootSettingsMenu[] { * Advanced Menu * Exit */ -{ (const char*) SettingsDescriptions[0], { settings_setInputVRange }, { - settings_displayInputVRange } }, /*Voltage input*/ -{ (const char*) SettingsMenuEntriesDescriptions[0], { - settings_enterSolderingMenu }, { settings_displaySolderingMenu } }, /*Soldering*/ -{ (const char*) SettingsMenuEntriesDescriptions[1], { settings_enterPowerMenu }, - { settings_displayPowerMenu } }, /*Sleep Options Menu*/ -{ (const char*) SettingsMenuEntriesDescriptions[2], { settings_enterUIMenu }, { - settings_displayUIMenu } }, /*UI Menu*/ -{ (const char*) SettingsMenuEntriesDescriptions[3], - { settings_enterAdvancedMenu }, { settings_displayAdvancedMenu } }, /*Advanced Menu*/ -{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE +#ifdef MODEL_TS100 + {(const char*)SettingsDescriptions[0], + {settings_setInputVRange}, + {settings_displayInputVRange}}, /*Voltage input*/ +#else + {(const char*)SettingsDescriptions[20], + {settings_setInputPRange}, + {settings_displayInputPRange}}, /*Voltage input*/ +#endif + {(const char*)NULL, + {settings_enterSolderingMenu}, + {settings_displaySolderingMenu}}, /*Soldering*/ + {(const char*)NULL, + {settings_enterPowerMenu}, + {settings_displayPowerMenu}}, /*Sleep Options Menu*/ + {(const char*)NULL, + {settings_enterUIMenu}, + {settings_displayUIMenu}}, /*UI Menu*/ + {(const char*)NULL, + {settings_enterAdvancedMenu}, + {settings_displayAdvancedMenu}}, /*Advanced Menu*/ + {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE }; const menuitem solderingMenu[] = { -/* - * Boost Mode Enabled - * Boost Mode Temp - * Auto Start - */ -{ (const char*) SettingsDescriptions[8], { settings_setBoostModeEnabled }, { - settings_displayBoostModeEnabled } }, /*Enable Boost*/ -{ (const char*) SettingsDescriptions[9], { settings_setBoostTemp }, { - settings_displayBoostTemp } }, /*Boost Temp*/ -{ (const char*) SettingsDescriptions[10], { settings_setAutomaticStartMode }, { - settings_displayAutomaticStartMode } }, /*Auto start*/ -{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE + /* + * Boost Mode Enabled + * Boost Mode Temp + * Auto Start + */ + {(const char*)SettingsDescriptions[8], + {settings_setBoostModeEnabled}, + {settings_displayBoostModeEnabled}}, /*Enable Boost*/ + {(const char*)SettingsDescriptions[9], + {settings_setBoostTemp}, + {settings_displayBoostTemp}}, /*Boost Temp*/ + {(const char*)SettingsDescriptions[10], + {settings_setAutomaticStartMode}, + {settings_displayAutomaticStartMode}}, /*Auto start*/ + {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE }; const menuitem UIMenu[] = { -/* - // Language - * Scrolling Speed - * Temperature Unit - * Display orientation - * Cooldown blink - */ -{ (const char*) SettingsDescriptions[5], { settings_setTempF }, { - settings_displayTempF } }, /* Temperature units*/ -{ (const char*) SettingsDescriptions[7], { settings_setDisplayRotation }, { - settings_displayDisplayRotation } }, /*Display Rotation*/ -{ (const char*) SettingsDescriptions[11], { settings_setCoolingBlinkEnabled }, { - settings_displayCoolingBlinkEnabled } }, /*Cooling blink warning*/ -{ (const char*) SettingsDescriptions[16], { settings_setScrollSpeed }, { - settings_displayScrollSpeed } }, /*Scroll Speed for descriptions*/ -{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE + /* + // Language + * Scrolling Speed + * Temperature Unit + * Display orientation + * Cooldown blink + */ + {(const char*)SettingsDescriptions[5], + {settings_setTempF}, + {settings_displayTempF}}, /* Temperature units*/ + {(const char*)SettingsDescriptions[7], + {settings_setDisplayRotation}, + {settings_displayDisplayRotation}}, /*Display Rotation*/ + {(const char*)SettingsDescriptions[11], + {settings_setCoolingBlinkEnabled}, + {settings_displayCoolingBlinkEnabled}}, /*Cooling blink warning*/ + {(const char*)SettingsDescriptions[16], + {settings_setScrollSpeed}, + {settings_displayScrollSpeed}}, /*Scroll Speed for descriptions*/ + {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE }; const menuitem PowerMenu[] = { -/* - * Sleep Temp - * Sleep Time - * Shutdown Time - * Motion Sensitivity - */ -{ (const char*) SettingsDescriptions[1], { settings_setSleepTemp }, { - settings_displaySleepTemp } }, /*Sleep Temp*/ -{ (const char*) SettingsDescriptions[2], { settings_setSleepTime }, { - settings_displaySleepTime } }, /*Sleep Time*/ -{ (const char*) SettingsDescriptions[3], { settings_setShutdownTime }, { - settings_displayShutdownTime } }, /*Shutdown Time*/ -{ (const char*) SettingsDescriptions[4], { settings_setSensitivity }, { - settings_displaySensitivity } }, /* Motion Sensitivity*/ -{ NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE + /* + * Sleep Temp + * Sleep Time + * Shutdown Time + * Motion Sensitivity + */ + {(const char*)SettingsDescriptions[1], + {settings_setSleepTemp}, + {settings_displaySleepTemp}}, /*Sleep Temp*/ + {(const char*)SettingsDescriptions[2], + {settings_setSleepTime}, + {settings_displaySleepTime}}, /*Sleep Time*/ + {(const char*)SettingsDescriptions[3], + {settings_setShutdownTime}, + {settings_displayShutdownTime}}, /*Shutdown Time*/ + {(const char*)SettingsDescriptions[4], + {settings_setSensitivity}, + {settings_displaySensitivity}}, /* Motion Sensitivity*/ + {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE }; const menuitem advancedMenu[] = { -/* - * Detailed IDLE - * Detailed Soldering - * Logo Time - * Calibrate Temperature - * Calibrate Input V - * Reset Settings - */ -{ (const char*) SettingsDescriptions[6], { settings_setAdvancedIDLEScreens }, { - settings_displayAdvancedIDLEScreens } }, /* Advanced idle screen*/ -{ (const char*) SettingsDescriptions[15], - { settings_setAdvancedSolderingScreens }, { - settings_displayAdvancedSolderingScreens } }, /* Advanced soldering screen*/ -{ (const char*) SettingsDescriptions[13], { settings_setResetSettings }, { - settings_displayResetSettings } }, /*Resets settings*/ -{ (const char*) SettingsDescriptions[17], { settings_setTipModel }, { - settings_displayTipModel } }, /*Select tip Model */ -{ (const char*) SettingsDescriptions[12], { settings_setCalibrate }, { - settings_displayCalibrate } }, /*Calibrate tip*/ -{ (const char*) SettingsDescriptions[14], { settings_setCalibrateVIN }, { - settings_displayCalibrateVIN } }, /*Voltage input cal*/ -#ifdef PIDSETTINGS - - { (const char*) SettingsDescriptions[17], {settings_setPIDP}, { - settings_displayPIDP}}, /*Voltage input cal*/ - { (const char*) SettingsDescriptions[18], {settings_setPIDI}, { - settings_displayPIDI}}, /*Voltage input cal*/ - { (const char*) SettingsDescriptions[19], {settings_setPIDD}, { - settings_displayPIDD}}, /*Voltage input cal*/ -#endif - { NULL, { NULL }, { NULL } } // end of menu marker. DO NOT REMOVE + /* + * Detailed IDLE + * Detailed Soldering + * Logo Time + * Calibrate Temperature + * Calibrate Input V + * Reset Settings + */ + {(const char*)SettingsDescriptions[6], + {settings_setAdvancedIDLEScreens}, + {settings_displayAdvancedIDLEScreens}}, /* Advanced idle screen*/ + {(const char*)SettingsDescriptions[15], + {settings_setAdvancedSolderingScreens}, + {settings_displayAdvancedSolderingScreens}}, /* Advanced soldering screen*/ + {(const char*)SettingsDescriptions[13], + {settings_setResetSettings}, + {settings_displayResetSettings}}, /*Resets settings*/ + {(const char*)SettingsDescriptions[17], + {settings_setTipModel}, + {settings_displayTipModel}}, /*Select tip Model */ + {(const char*)SettingsDescriptions[12], + {settings_setCalibrate}, + {settings_displayCalibrate}}, /*Calibrate tip*/ + {(const char*)SettingsDescriptions[14], + {settings_setCalibrateVIN}, + {settings_displayCalibrateVIN}}, /*Voltage input cal*/ + {NULL, {NULL}, {NULL}} // end of menu marker. DO NOT REMOVE }; -const menuitem calibrationMenu[] { { (const char*) SettingsDescriptions[6], { - calibration_enterSimpleCal }, { calibration_displaySimpleCal } }, -/* Simple Cal*/ -{ (const char*) SettingsDescriptions[6], { calibration_enterAdvancedCal }, { - calibration_displayAdvancedCal } }, /* Advanced Cal */ -{ NULL, { NULL }, { NULL } } }; +const menuitem calibrationMenu[]{ + {(const char*)SettingsDescriptions[6], + {calibration_enterSimpleCal}, + {calibration_displaySimpleCal}}, + /* Simple Cal*/ + {(const char*)SettingsDescriptions[6], + {calibration_enterAdvancedCal}, + {calibration_displayAdvancedCal}}, /* Advanced Cal */ + {NULL, {NULL}, {NULL}}}; static void printShortDescriptionSingleLine(uint32_t shortDescIndex) { - lcd.setFont(0); - lcd.setCharCursor(0, 0); - lcd.print(SettingsShortNames[shortDescIndex][0]); + OLED::setFont(0); + OLED::setCharCursor(0, 0); + OLED::print(SettingsShortNames[shortDescIndex][0]); } static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) { - lcd.setFont(1); - lcd.setCharCursor(0, 0); - lcd.print(SettingsShortNames[shortDescIndex][0]); - lcd.setCharCursor(0, 1); - lcd.print(SettingsShortNames[shortDescIndex][1]); + OLED::setFont(1); + OLED::setCharCursor(0, 0); + OLED::print(SettingsShortNames[shortDescIndex][0]); + OLED::setCharCursor(0, 1); + OLED::print(SettingsShortNames[shortDescIndex][1]); } /** @@ -232,454 +259,497 @@ static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) { * description. */ static void printShortDescription(uint32_t shortDescIndex, - uint16_t cursorCharPosition) { - // print short description (default single line, explicit double line) - if (SettingsShortNameType == SHORT_NAME_DOUBLE_LINE) { - printShortDescriptionDoubleLine(shortDescIndex); - } else { - printShortDescriptionSingleLine(shortDescIndex); - } + uint16_t cursorCharPosition) { + // print short description (default single line, explicit double line) + if (SettingsShortNameType == SHORT_NAME_DOUBLE_LINE) { + printShortDescriptionDoubleLine(shortDescIndex); + } else { + printShortDescriptionSingleLine(shortDescIndex); + } - // prepare cursor for value - lcd.setFont(0); - lcd.setCharCursor(cursorCharPosition, 0); + // prepare cursor for value + OLED::setFont(0); + OLED::setCharCursor(cursorCharPosition, 0); } static int userConfirmation(const char* message) { - uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7); - uint32_t messageStart = xTaskGetTickCount(); + uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7); + uint32_t messageStart = xTaskGetTickCount(); - lcd.setFont(0); - lcd.setCursor(0, 0); - int16_t lastOffset = -1; - bool lcdRefresh = true; + OLED::setFont(0); + OLED::setCursor(0, 0); + int16_t lastOffset = -1; + bool lcdRefresh = true; - for (;;) { + for (;;) { + int16_t messageOffset = + ((xTaskGetTickCount() - messageStart) / + (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); + messageOffset %= messageWidth; // Roll around at the end - int16_t messageOffset = ((xTaskGetTickCount() - messageStart) - / (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); - messageOffset %= messageWidth; //Roll around at the end + if (lastOffset != messageOffset) { + OLED::clearScreen(); - if (lastOffset != messageOffset) { - lcd.clearScreen(); + //^ Rolling offset based on time + OLED::setCursor((OLED_WIDTH - messageOffset), 0); + OLED::print(message); + lastOffset = messageOffset; + lcdRefresh = true; + } - //^ Rolling offset based on time - lcd.setCursor((OLED_WIDTH - messageOffset), 0); - lcd.print(message); - lastOffset = messageOffset; - lcdRefresh = true; - } + ButtonState buttons = getButtonState(); + switch (buttons) { + case BUTTON_F_SHORT: + // User confirmed + return 1; - ButtonState buttons = getButtonState(); - switch (buttons) { - case BUTTON_F_SHORT: - //User confirmed - return 1; + case BUTTON_NONE: + break; + default: + case BUTTON_BOTH: + case BUTTON_B_SHORT: + case BUTTON_F_LONG: + case BUTTON_B_LONG: + return 0; + } - case BUTTON_NONE: - break; - default: - case BUTTON_BOTH: - case BUTTON_B_SHORT: - case BUTTON_F_LONG: - case BUTTON_B_LONG: - return 0; - } - - if (lcdRefresh) { - lcd.refresh(); - osDelay(40); - lcdRefresh = false; - } - } - return 0; + if (lcdRefresh) { + OLED::refresh(); + osDelay(40); + lcdRefresh = false; + } + } + return 0; } - +#ifdef MODEL_TS100 static void settings_setInputVRange(void) { - systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 5; + systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 5; } static void settings_displayInputVRange(void) { - printShortDescription(0, 6); + printShortDescription(0, 6); - if (systemSettings.cutoutSetting) { - lcd.drawChar('0' + 2 + systemSettings.cutoutSetting); - lcd.drawChar('S'); - } else { - lcd.print("DC"); - } + if (systemSettings.cutoutSetting) { + OLED::drawChar('0' + 2 + systemSettings.cutoutSetting); + OLED::drawChar('S'); + } else { + OLED::print("DC"); + } +} +#else +static void settings_setInputPRange(void) { + systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 2; } +static void settings_displayInputPRange(void) { + printShortDescription(0, 5); +//0 = 18W, 1=24W + switch(systemSettings.cutoutSetting) + { + case 0: + OLED::print("18W"); + break; + case 1: + OLED::print("24W"); + break; + default: + break; + } + +} + +#endif static void settings_setSleepTemp(void) { - //If in C, 10 deg, if in F 20 deg - if (systemSettings.temperatureInF) { - systemSettings.SleepTemp += 20; - if (systemSettings.SleepTemp > 580) - systemSettings.SleepTemp = 120; - } else { - systemSettings.SleepTemp += 10; - if (systemSettings.SleepTemp > 300) - systemSettings.SleepTemp = 50; - } + // If in C, 10 deg, if in F 20 deg + if (systemSettings.temperatureInF) { + systemSettings.SleepTemp += 20; + if (systemSettings.SleepTemp > 580) systemSettings.SleepTemp = 120; + } else { + systemSettings.SleepTemp += 10; + if (systemSettings.SleepTemp > 300) systemSettings.SleepTemp = 50; + } } static void settings_displaySleepTemp(void) { - printShortDescription(1, 5); - lcd.printNumber(systemSettings.SleepTemp, 3); + printShortDescription(1, 5); + OLED::printNumber(systemSettings.SleepTemp, 3); } static void settings_setSleepTime(void) { - systemSettings.SleepTime++; // Go up 1 minute at a time - if (systemSettings.SleepTime >= 16) { - systemSettings.SleepTime = 0; // can't set time over 10 mins - } - // Remember that ^ is the time of no movement - if (PCBVersion == 3) - systemSettings.SleepTime = 0; //Disable sleep on no accel + systemSettings.SleepTime++; // Go up 1 minute at a time + if (systemSettings.SleepTime >= 16) { + systemSettings.SleepTime = 0; // can't set time over 10 mins + } + // Remember that ^ is the time of no movement + if (PCBVersion == 3) + systemSettings.SleepTime = 0; // Disable sleep on no accel } static void settings_displaySleepTime(void) { - printShortDescription(2, 5); - if (systemSettings.SleepTime == 0) { - lcd.print(OffString); - } else if (systemSettings.SleepTime < 6) { - lcd.printNumber(systemSettings.SleepTime * 10, 2); - lcd.drawChar('S'); - } else { - lcd.printNumber(systemSettings.SleepTime - 5, 2); - lcd.drawChar('M'); - } + printShortDescription(2, 5); + if (systemSettings.SleepTime == 0) { + OLED::print(OffString); + } else if (systemSettings.SleepTime < 6) { + OLED::printNumber(systemSettings.SleepTime * 10, 2); + OLED::drawChar('S'); + } else { + OLED::printNumber(systemSettings.SleepTime - 5, 2); + OLED::drawChar('M'); + } } static void settings_setShutdownTime(void) { - systemSettings.ShutdownTime++; - if (systemSettings.ShutdownTime > 60) { - systemSettings.ShutdownTime = 0; // wrap to off - } - if (PCBVersion == 3) - systemSettings.ShutdownTime = 0; //Disable shutdown on no accel + systemSettings.ShutdownTime++; + if (systemSettings.ShutdownTime > 60) { + systemSettings.ShutdownTime = 0; // wrap to off + } + if (PCBVersion == 3) + systemSettings.ShutdownTime = 0; // Disable shutdown on no accel } static void settings_displayShutdownTime(void) { - printShortDescription(3, 5); - if (systemSettings.ShutdownTime == 0) { - lcd.print(OffString); - } else { - lcd.printNumber(systemSettings.ShutdownTime, 2); - lcd.drawChar('M'); - } + printShortDescription(3, 5); + if (systemSettings.ShutdownTime == 0) { + OLED::print(OffString); + } else { + OLED::printNumber(systemSettings.ShutdownTime, 2); + OLED::drawChar('M'); + } } static void settings_setTempF(void) { - systemSettings.temperatureInF = !systemSettings.temperatureInF; - if (systemSettings.temperatureInF) { - //Change sleep, boost and soldering temps to the F equiv - //C to F == F= ( (C*9) +160)/5 - systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5; - systemSettings.SolderingTemp = - ((systemSettings.SolderingTemp * 9) + 160) / 5; - systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5; - } else { - //Change sleep, boost and soldering temps to the C equiv - // F->C == C = ((F-32)*5)/9 - systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9; - systemSettings.SolderingTemp = ((systemSettings.SolderingTemp - 32) * 5) - / 9; - systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9; - - } - // Rescale both to be multiples of 10 - systemSettings.BoostTemp = systemSettings.BoostTemp / 10; - systemSettings.BoostTemp *= 10; - systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10; - systemSettings.SolderingTemp *= 10; - systemSettings.SleepTemp = systemSettings.SleepTemp / 10; - systemSettings.SleepTemp *= 10; - + systemSettings.temperatureInF = !systemSettings.temperatureInF; + if (systemSettings.temperatureInF) { + // Change sleep, boost and soldering temps to the F equiv + // C to F == F= ( (C*9) +160)/5 + systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5; + systemSettings.SolderingTemp = + ((systemSettings.SolderingTemp * 9) + 160) / 5; + systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5; + } else { + // Change sleep, boost and soldering temps to the C equiv + // F->C == C = ((F-32)*5)/9 + systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9; + systemSettings.SolderingTemp = + ((systemSettings.SolderingTemp - 32) * 5) / 9; + systemSettings.SleepTemp = ((systemSettings.SleepTemp - 32) * 5) / 9; + } + // Rescale both to be multiples of 10 + systemSettings.BoostTemp = systemSettings.BoostTemp / 10; + systemSettings.BoostTemp *= 10; + systemSettings.SolderingTemp = systemSettings.SolderingTemp / 10; + systemSettings.SolderingTemp *= 10; + systemSettings.SleepTemp = systemSettings.SleepTemp / 10; + systemSettings.SleepTemp *= 10; } static void settings_displayTempF(void) { - printShortDescription(5, 7); + printShortDescription(5, 7); - lcd.drawChar((systemSettings.temperatureInF) ? 'F' : 'C'); + OLED::drawChar((systemSettings.temperatureInF) ? 'F' : 'C'); } static void settings_setSensitivity(void) { - systemSettings.sensitivity++; - systemSettings.sensitivity = systemSettings.sensitivity % 10; + systemSettings.sensitivity++; + systemSettings.sensitivity = systemSettings.sensitivity % 10; } static void settings_displaySensitivity(void) { - printShortDescription(4, 7); - lcd.printNumber(systemSettings.sensitivity, 1); + printShortDescription(4, 7); + OLED::printNumber(systemSettings.sensitivity, 1); } static void settings_setAdvancedSolderingScreens(void) { - systemSettings.detailedSoldering = !systemSettings.detailedSoldering; + systemSettings.detailedSoldering = !systemSettings.detailedSoldering; } static void settings_displayAdvancedSolderingScreens(void) { - printShortDescription(15, 7); + printShortDescription(15, 7); - lcd.drawCheckbox(systemSettings.detailedSoldering); + OLED::drawCheckbox(systemSettings.detailedSoldering); } static void settings_setAdvancedIDLEScreens(void) { - systemSettings.detailedIDLE = !systemSettings.detailedIDLE; + systemSettings.detailedIDLE = !systemSettings.detailedIDLE; } static void settings_displayAdvancedIDLEScreens(void) { - printShortDescription(6, 7); + printShortDescription(6, 7); - lcd.drawCheckbox(systemSettings.detailedIDLE); + OLED::drawCheckbox(systemSettings.detailedIDLE); } static void settings_setScrollSpeed(void) { - - if (systemSettings.descriptionScrollSpeed == 0) - systemSettings.descriptionScrollSpeed = 1; - else - systemSettings.descriptionScrollSpeed = 0; + if (systemSettings.descriptionScrollSpeed == 0) + systemSettings.descriptionScrollSpeed = 1; + else + systemSettings.descriptionScrollSpeed = 0; } static void settings_displayScrollSpeed(void) { - printShortDescription(16, 7); - lcd.drawChar( - (systemSettings.descriptionScrollSpeed) ? - SettingFastChar : SettingSlowChar); + printShortDescription(16, 7); + OLED::drawChar((systemSettings.descriptionScrollSpeed) ? SettingFastChar + : SettingSlowChar); } static void settings_setDisplayRotation(void) { - systemSettings.OrientationMode++; - systemSettings.OrientationMode = systemSettings.OrientationMode % 3; - switch (systemSettings.OrientationMode) { - case 0: - lcd.setRotation(false); - break; - case 1: - lcd.setRotation(true); - break; - case 2: - //do nothing on auto - break; - default: - break; - } + systemSettings.OrientationMode++; + systemSettings.OrientationMode = systemSettings.OrientationMode % 3; + switch (systemSettings.OrientationMode) { + case 0: + OLED::setRotation(false); + break; + case 1: + OLED::setRotation(true); + break; + case 2: + // do nothing on auto + break; + default: + break; + } } static void settings_displayDisplayRotation(void) { - printShortDescription(7, 7); + printShortDescription(7, 7); - switch (systemSettings.OrientationMode) { - case 0: - lcd.drawChar(SettingRightChar); - break; - case 1: - lcd.drawChar(SettingLeftChar); - break; - case 2: - lcd.drawChar(SettingAutoChar); - break; - default: - lcd.drawChar(SettingRightChar); - break; - } + switch (systemSettings.OrientationMode) { + case 0: + OLED::drawChar(SettingRightChar); + break; + case 1: + OLED::drawChar(SettingLeftChar); + break; + case 2: + OLED::drawChar(SettingAutoChar); + break; + default: + OLED::drawChar(SettingRightChar); + break; + } } static void settings_setBoostModeEnabled(void) { - systemSettings.boostModeEnabled = !systemSettings.boostModeEnabled; + systemSettings.boostModeEnabled = !systemSettings.boostModeEnabled; } static void settings_displayBoostModeEnabled(void) { - printShortDescription(8, 7); + printShortDescription(8, 7); - lcd.drawCheckbox(systemSettings.boostModeEnabled); + OLED::drawCheckbox(systemSettings.boostModeEnabled); } static void settings_setBoostTemp(void) { - - if (systemSettings.temperatureInF) { - systemSettings.BoostTemp += 20; // Go up 20F at a time - if (systemSettings.BoostTemp > 850) { - systemSettings.BoostTemp = 480; // loop back at 250 - } - } else { - systemSettings.BoostTemp += 10; // Go up 10C at a time - if (systemSettings.BoostTemp > 450) { - systemSettings.BoostTemp = 250; // loop back at 250 - } - } + if (systemSettings.temperatureInF) { + systemSettings.BoostTemp += 20; // Go up 20F at a time + if (systemSettings.BoostTemp > 850) { + systemSettings.BoostTemp = 480; // loop back at 250 + } + } else { + systemSettings.BoostTemp += 10; // Go up 10C at a time + if (systemSettings.BoostTemp > 450) { + systemSettings.BoostTemp = 250; // loop back at 250 + } + } } static void settings_displayBoostTemp(void) { - printShortDescription(9, 5); - lcd.printNumber(systemSettings.BoostTemp, 3); + printShortDescription(9, 5); + OLED::printNumber(systemSettings.BoostTemp, 3); } static void settings_setAutomaticStartMode(void) { - systemSettings.autoStartMode++; - systemSettings.autoStartMode %= 2; + systemSettings.autoStartMode++; + systemSettings.autoStartMode %= 2; } static void settings_displayAutomaticStartMode(void) { - printShortDescription(10, 7); - lcd.drawCheckbox(systemSettings.autoStartMode); + printShortDescription(10, 7); + OLED::drawCheckbox(systemSettings.autoStartMode); } static void settings_setCoolingBlinkEnabled(void) { - systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink; + systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink; } static void settings_displayCoolingBlinkEnabled(void) { - printShortDescription(11, 7); + printShortDescription(11, 7); - lcd.drawCheckbox(systemSettings.coolingTempBlink); + OLED::drawCheckbox(systemSettings.coolingTempBlink); } static void settings_setResetSettings(void) { - if (userConfirmation(SettingsResetWarning)) { - resetSettings(); + if (userConfirmation(SettingsResetWarning)) { + resetSettings(); - lcd.setFont(0); - lcd.setCursor(0, 0); - lcd.print("RESET OK"); - lcd.refresh(); + OLED::setFont(0); + OLED::setCursor(0, 0); + OLED::print("RESET OK"); + OLED::refresh(); - waitForButtonPressOrTimeout(200); - } + waitForButtonPressOrTimeout(200); // 2 second timeout + } } static void settings_displayResetSettings(void) { - printShortDescription(13, 7); + printShortDescription(13, 7); } static void settings_setTipModel(void) { - systemSettings.tipType++; - systemSettings.tipType %= (Tip_Custom + 1); //Wrap after custom - + systemSettings.tipType++; + systemSettings.tipType %= (Tip_Custom + 1); // Wrap after custom } static void settings_displayTipModel(void) { - printShortDescription(17, 4); - //Print in small text the tip model - lcd.setFont(1); - //set the cursor - //Print the mfg - lcd.setCursor(40, 0); - if (systemSettings.tipType < Tip_MiniWare) { - lcd.print("TS100"); - } else if (systemSettings.tipType < Tip_Hakko) { - lcd.print("HAKKO"); - } else if (systemSettings.tipType == Tip_Custom) { - lcd.print("User"); - } - lcd.setCursor(40, 8); - switch ((enum TipType) systemSettings.tipType) { - case TS_B2: - lcd.print(" B2 "); - break; - case TS_D24: - lcd.print(" D24 "); - break; - case TS_BC2: - lcd.print(" BC2 "); - break; - case TS_C1: - lcd.print(" C1 "); - break; - case HAKKO_BC2: - lcd.print(" BC2 "); - break; - case Tip_Custom: - lcd.print("Tuned"); - break; - default: - lcd.print("????"); - break; - } -} -static void calibration_displaySimpleCal(void) { - printShortDescription(18, 5); + printShortDescription(17, 4); + // Print in small text the tip model + OLED::setFont(1); + // set the cursor + // Print the mfg + OLED::setCursor(40, 0); + if (systemSettings.tipType < Tip_MiniWare) { +#ifdef MODEL_TS100 + OLED::print("TS100"); +#else + OLED::print("TS80"); +#endif + } +#ifdef MODEL_TS100 + else if (systemSettings.tipType < Tip_Hakko) { + OLED::print("HAKKO"); + } +#endif + else if (systemSettings.tipType == Tip_Custom) { + OLED::print("User"); + } + OLED::setCursor(40, 8); +#ifdef MODEL_TS100 + switch ((enum TipType)systemSettings.tipType) { + case TS_B2: + OLED::print(" B2 "); + break; + case TS_D24: + OLED::print(" D24 "); + break; + case TS_BC2: + OLED::print(" BC2 "); + break; + case TS_C1: + OLED::print(" C1 "); + break; + case HAKKO_BC2: + OLED::print(" BC2 "); + break; + case Tip_Custom: + OLED::print("Tuned"); + break; + default: + OLED::print("????"); + break; + } +#endif +#ifdef MODEL_TS80 + // only 2 tips atm + switch ((enum TipType)systemSettings.tipType) { + case TS_B02: + OLED::print(" B02 "); + break; + case TS_D25: + OLED::print(" D25 "); + break; + case Tip_Custom: + OLED::print("Tuned"); + break; + default: + OLED::print("????"); + break; + } +#endif } +static void calibration_displaySimpleCal(void) { printShortDescription(18, 5); } static void dotDelay() { - for (uint8_t i = 0; i < 20; i++) { - getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable. - lcd.clearScreen(); - lcd.setCursor(0, 0); - for (uint8_t x = 0; x < i / 4; x++) - lcd.print("."); - lcd.refresh(); - osDelay(50); - } + for (uint8_t i = 0; i < 20; i++) { + getTipRawTemp( + 1); // cycle through the filter a fair bit to ensure we're stable. + OLED::clearScreen(); + OLED::setCursor(0, 0); + for (uint8_t x = 0; x < i / 4; x++) OLED::print("."); + OLED::refresh(); + osDelay(50); + } } static void setTipOffset() { - setCalibrationOffset(0); //turn off the current offset - dotDelay(); + setCalibrationOffset(0); // turn off the current offset + dotDelay(); - //If the thermocouple at the end of the tip, and the handle are at equalibrium, then the output should be zero, as there is no temperature differential. + // If the thermocouple at the end of the tip, and the handle are at + // equalibrium, then the output should be zero, as there is no temperature + // differential. - int32_t offset = 0; - for (uint8_t i = 0; i < 15; i++) { - offset += getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable. + int32_t offset = 0; + for (uint8_t i = 0; i < 15; i++) { + offset += getTipRawTemp( + 1); // cycle through the filter a fair bit to ensure we're stable. - lcd.clearScreen(); - lcd.setCursor(0, 0); + OLED::clearScreen(); + OLED::setCursor(0, 0); - for (uint8_t x = 0; x < i / 4; x++) - lcd.print("."); - lcd.refresh(); - osDelay(200); - } - systemSettings.CalibrationOffset = offset / 15; - setCalibrationOffset(systemSettings.CalibrationOffset); //store the error - osDelay(100); + for (uint8_t x = 0; x < i / 4; x++) OLED::print("."); + OLED::refresh(); + osDelay(200); + } + systemSettings.CalibrationOffset = offset / 15; + setCalibrationOffset(systemSettings.CalibrationOffset); // store the error + osDelay(100); } static void calibration_enterSimpleCal(void) { -//User has entered into the simple cal routine - if (userConfirmation(SettingsCalibrationWarning)) { - //User has confirmed their handle is at ambient - //So take the offset measurement - setTipOffset(); - //Next we want the user to put the tip into 100C water so we can calculate their tip's gain - //Gain is the m term from rise/run plot of raw readings vs (tip-handle) - //Thus we want to calculate ([TipRawHot-TipRawCold])/(ActualHot-HandleHot)-(ActualCold-HandleCold) - //Thus we first need to store -> TiprawCold,HandleCold,ActualCold==HandleCold -> RawTipCold - uint32_t RawTipCold = getTipRawTemp(0) * 10; - lcd.clearScreen(); - lcd.setCursor(0, 0); - lcd.setFont(1); - lcd.print("Please Insert Tip\nInto Boiling Water"); - lcd.refresh(); - osDelay(200); - waitForButtonPress(); - dotDelay(); //cycle the filter a bit - //Now take the three hot measurements - //Assume water is boiling at 100C - uint32_t RawTipHot = getTipRawTemp(0) * 10; - uint32_t HandleTempHot = getHandleTemperature() / 10; + // User has entered into the simple cal routine + if (userConfirmation(SettingsCalibrationWarning)) { + // User has confirmed their handle is at ambient + // So take the offset measurement + setTipOffset(); + // Next we want the user to put the tip into 100C water so we can calculate + // their tip's gain Gain is the m term from rise/run plot of raw readings vs + // (tip-handle) Thus we want to calculate + // ([TipRawHot-TipRawCold])/(ActualHot-HandleHot)-(ActualCold-HandleCold) + // Thus we first need to store -> + // TiprawCold,HandleCold,ActualCold==HandleCold -> RawTipCold + uint32_t RawTipCold = getTipRawTemp(0) * 10; + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::setFont(1); + OLED::print("Please Insert Tip\nInto Boiling Water"); + OLED::refresh(); + osDelay(200); + waitForButtonPress(); + dotDelay(); // cycle the filter a bit + // Now take the three hot measurements + // Assume water is boiling at 100C + uint32_t RawTipHot = getTipRawTemp(0) * 10; + uint32_t HandleTempHot = getHandleTemperature() / 10; - uint32_t gain = (RawTipHot - RawTipCold) / (100 - HandleTempHot); + uint32_t gain = (RawTipHot - RawTipCold) / (100 - HandleTempHot); - //Show this to the user - lcd.clearScreen(); - lcd.setCursor(0, 0); - lcd.print("Your G: "); - lcd.printNumber(gain, 6); - lcd.print("\n~= 120-140"); - lcd.refresh(); - osDelay(2000); - waitForButtonPress(); - lcd.clearScreen(); - lcd.setCursor(0, 0); - lcd.print("H: "); - lcd.printNumber(RawTipHot, 8); - lcd.setCursor(0, 8); - lcd.print("C: "); - lcd.printNumber(RawTipCold, 8); - lcd.refresh(); - osDelay(2000); - waitForButtonPress(); - } + // Show this to the user + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print("Your G: "); + OLED::printNumber(gain, 6); + OLED::print("\n~= 120-140"); + OLED::refresh(); + osDelay(2000); + waitForButtonPress(); + OLED::clearScreen(); + OLED::setCursor(0, 0); + OLED::print("H: "); + OLED::printNumber(RawTipHot, 8); + OLED::setCursor(0, 8); + OLED::print("C: "); + OLED::printNumber(RawTipCold, 8); + OLED::refresh(); + osDelay(2000); + waitForButtonPress(); + } } static void calibration_displayAdvancedCal(void) { - printShortDescription(19, 5); + printShortDescription(19, 5); } static void calibration_enterAdvancedCal(void) { //Advanced cal @@ -721,22 +791,22 @@ static void calibration_enterAdvancedCal(void) { systemSettings.customTipGain = 200; else if (systemSettings.customTipGain <= 100) systemSettings.customTipGain = 100; - lcd.setCursor(0, 0); - lcd.clearScreen(); - lcd.setFont(0); - if (lcd.getRotation()) - lcd.drawChar('-'); + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); + if (OLED::getRotation()) + OLED::drawChar('-'); else - lcd.drawChar('+'); + OLED::drawChar('+'); - lcd.drawChar(' '); - lcd.printNumber(systemSettings.customTipGain, 4); - lcd.drawChar(' '); - if (lcd.getRotation()) - lcd.drawChar('+'); + OLED::drawChar(' '); + OLED::printNumber(systemSettings.customTipGain, 4); + OLED::drawChar(' '); + if (OLED::getRotation()) + OLED::drawChar('+'); else - lcd.drawChar('-'); - lcd.refresh(); + OLED::drawChar('-'); + OLED::refresh(); GUIDelay(); } // Wait for the user to confirm the exit message that the calibration is done @@ -746,228 +816,205 @@ static void calibration_enterAdvancedCal(void) { //Provide the user the option to tune their own tip if custom is selected //If not only do single point tuning as per usual static void settings_setCalibrate(void) { - if (systemSettings.tipType == Tip_Custom) { - //Two types of calibration - //1. Basic, idle temp + hot water (100C) - //2. Advanced, 100C + 350C, we keep PID tracking to a temperature target - return gui_Menu(calibrationMenu); - } - //Else - // Ask user if handle is at the tip temperature - // Any error between handle and the tip will be a direct offset in the control loop + if (systemSettings.tipType == Tip_Custom) { + // Two types of calibration + // 1. Basic, idle temp + hot water (100C) + // 2. Advanced, 100C + 350C, we keep PID tracking to a temperature target + return gui_Menu(calibrationMenu); + } + // Else + // Ask user if handle is at the tip temperature + // Any error between handle and the tip will be a direct offset in the control + // loop - else if (userConfirmation(SettingsCalibrationWarning)) { - //User confirmed - //So we now perform the actual calculation - setTipOffset(); - - } + else if (userConfirmation(SettingsCalibrationWarning)) { + // User confirmed + // So we now perform the actual calculation + setTipOffset(); + } } -static void settings_displayCalibrate(void) { - printShortDescription(12, 5); -} +static void settings_displayCalibrate(void) { printShortDescription(12, 5); } static void settings_setCalibrateVIN(void) { - // Jump to the voltage calibration subscreen - lcd.setFont(0); - lcd.clearScreen(); - lcd.setCursor(0, 0); + // Jump to the voltage calibration subscreen + OLED::setFont(0); + OLED::clearScreen(); + OLED::setCursor(0, 0); - for (;;) { - lcd.setCursor(0, 0); - lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2); - lcd.print("."); - lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1); - lcd.print("V"); + for (;;) { + OLED::setCursor(0, 0); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2); + OLED::print("."); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1); + OLED::print("V"); - ButtonState buttons = getButtonState(); - switch (buttons) { - case BUTTON_F_SHORT: - systemSettings.voltageDiv++; - break; + ButtonState buttons = getButtonState(); + switch (buttons) { + case BUTTON_F_SHORT: + systemSettings.voltageDiv++; + break; - case BUTTON_B_SHORT: - systemSettings.voltageDiv--; - break; + case BUTTON_B_SHORT: + systemSettings.voltageDiv--; + break; - case BUTTON_BOTH: - case BUTTON_F_LONG: - case BUTTON_B_LONG: - saveSettings(); - return; - break; - case BUTTON_NONE: - default: - break; - } + case BUTTON_BOTH: + case BUTTON_F_LONG: + case BUTTON_B_LONG: + saveSettings(); + return; + break; + case BUTTON_NONE: + default: + break; + } - lcd.refresh(); - osDelay(40); + OLED::refresh(); + osDelay(40); - // Cap to sensible values - if (systemSettings.voltageDiv < 360) { - systemSettings.voltageDiv = 360; - } else if (systemSettings.voltageDiv > 520) { - systemSettings.voltageDiv = 520; - } - } + // Cap to sensible values + if (systemSettings.voltageDiv < 360) { + systemSettings.voltageDiv = 360; + } else if (systemSettings.voltageDiv > 520) { + systemSettings.voltageDiv = 520; + } + } } static void displayMenu(size_t index) { - //Call into the menu - lcd.setFont(1); - lcd.setCursor(0, 0); - //Draw title - lcd.print(SettingsMenuEntries[index]); - //Draw symbol - //16 pixel wide image - lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index])); + // Call into the menu + OLED::setFont(1); + OLED::setCursor(0, 0); + // Draw title + OLED::print(SettingsMenuEntries[index]); + // Draw symbol + // 16 pixel wide image + OLED::drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index])); } -static void settings_displayCalibrateVIN(void) { - printShortDescription(14, 5); -} -static void settings_displaySolderingMenu(void) { - displayMenu(0); -} -static void settings_enterSolderingMenu(void) { - gui_Menu(solderingMenu); -} -static void settings_displayPowerMenu(void) { - displayMenu(1); -} -static void settings_enterPowerMenu(void) { - gui_Menu(PowerMenu); -} -static void settings_displayUIMenu(void) { - displayMenu(2); -} -static void settings_enterUIMenu(void) { - gui_Menu(UIMenu); -} -static void settings_displayAdvancedMenu(void) { - displayMenu(3); -} -static void settings_enterAdvancedMenu(void) { - gui_Menu(advancedMenu); -} +static void settings_displayCalibrateVIN(void) { printShortDescription(14, 5); } +static void settings_displaySolderingMenu(void) { displayMenu(0); } +static void settings_enterSolderingMenu(void) { gui_Menu(solderingMenu); } +static void settings_displayPowerMenu(void) { displayMenu(1); } +static void settings_enterPowerMenu(void) { gui_Menu(PowerMenu); } +static void settings_displayUIMenu(void) { displayMenu(2); } +static void settings_enterUIMenu(void) { gui_Menu(UIMenu); } +static void settings_displayAdvancedMenu(void) { displayMenu(3); } +static void settings_enterAdvancedMenu(void) { gui_Menu(advancedMenu); } void gui_Menu(const menuitem* menu) { - // Draw the settings menu and provide iteration support etc - uint8_t currentScreen = 0; - uint32_t autoRepeatTimer = 0; - uint8_t autoRepeatAcceleration = 0; - bool earlyExit = false; - uint32_t descriptionStart = 0; - int16_t lastOffset = -1; - bool lcdRefresh = true; - ButtonState lastButtonState = BUTTON_NONE; + // Draw the settings menu and provide iteration support etc + uint8_t currentScreen = 0; + uint32_t autoRepeatTimer = 0; + uint8_t autoRepeatAcceleration = 0; + bool earlyExit = false; + uint32_t descriptionStart = 0; + int16_t lastOffset = -1; + bool lcdRefresh = true; + ButtonState lastButtonState = BUTTON_NONE; - while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) { - lcd.setFont(0); - lcd.setCursor(0, 0); - //If the user has hesitated for >=3 seconds, show the long text - //Otherwise "draw" the option - if (xTaskGetTickCount() - lastButtonTime < 300) { - lcd.clearScreen(); - menu[currentScreen].draw.func(); - lastOffset = -1; - lcdRefresh = true; - } else { - // Draw description - if (descriptionStart == 0) - descriptionStart = xTaskGetTickCount(); - // lower the value - higher the speed - int16_t descriptionWidth = FONT_12_WIDTH - * (strlen(menu[currentScreen].description) + 7); - int16_t descriptionOffset = - ((xTaskGetTickCount() - descriptionStart) - / (systemSettings.descriptionScrollSpeed == 1 ? - 1 : 2)); - descriptionOffset %= descriptionWidth; //Roll around at the end + while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) { + OLED::setFont(0); + OLED::setCursor(0, 0); + // If the user has hesitated for >=3 seconds, show the long text + // Otherwise "draw" the option + if ((xTaskGetTickCount() - lastButtonTime < 300) || + menu[currentScreen].description == NULL) { + OLED::clearScreen(); + menu[currentScreen].draw.func(); + lastOffset = -1; + lcdRefresh = true; + } else { + // Draw description + if (descriptionStart == 0) descriptionStart = xTaskGetTickCount(); + // lower the value - higher the speed + int16_t descriptionWidth = + FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7); + int16_t descriptionOffset = + ((xTaskGetTickCount() - descriptionStart) / + (systemSettings.descriptionScrollSpeed == 1 ? 1 : 2)); + descriptionOffset %= descriptionWidth; // Roll around at the end - if (lastOffset != descriptionOffset) { - lcd.clearScreen(); + if (lastOffset != descriptionOffset) { + OLED::clearScreen(); - //^ Rolling offset based on time - lcd.setCursor((OLED_WIDTH - descriptionOffset), 0); - lcd.print(menu[currentScreen].description); - lastOffset = descriptionOffset; - lcdRefresh = true; - } + //^ Rolling offset based on time + OLED::setCursor((OLED_WIDTH - descriptionOffset), 0); + OLED::print(menu[currentScreen].description); + lastOffset = descriptionOffset; + lcdRefresh = true; + } + } - } + ButtonState buttons = getButtonState(); - ButtonState buttons = getButtonState(); + if (buttons != lastButtonState) { + autoRepeatAcceleration = 0; + lastButtonState = buttons; + } - if (buttons != lastButtonState) { - autoRepeatAcceleration = 0; - lastButtonState = buttons; - } + switch (buttons) { + case BUTTON_BOTH: + earlyExit = true; // will make us exit next loop + descriptionStart = 0; + break; + case BUTTON_F_SHORT: + // increment + if (descriptionStart == 0) { + if (menu[currentScreen].incrementHandler.func != NULL) + menu[currentScreen].incrementHandler.func(); + else + earlyExit = true; + } else + descriptionStart = 0; + break; + case BUTTON_B_SHORT: + if (descriptionStart == 0) + currentScreen++; + else + descriptionStart = 0; + break; + case BUTTON_F_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { + menu[currentScreen].incrementHandler.func(); + autoRepeatTimer = xTaskGetTickCount(); + descriptionStart = 0; - switch (buttons) { - case BUTTON_BOTH: - earlyExit = true; // will make us exit next loop - descriptionStart = 0; - break; - case BUTTON_F_SHORT: - // increment - if (descriptionStart == 0) { - if (menu[currentScreen].incrementHandler.func != NULL) - menu[currentScreen].incrementHandler.func(); - else - earlyExit = true; - } else - descriptionStart = 0; - break; - case BUTTON_B_SHORT: - if (descriptionStart == 0) - currentScreen++; - else - descriptionStart = 0; - break; - case BUTTON_F_LONG: - if (xTaskGetTickCount() - autoRepeatTimer - + autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) { - menu[currentScreen].incrementHandler.func(); - autoRepeatTimer = xTaskGetTickCount(); - descriptionStart = 0; + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_B_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { + currentScreen++; + autoRepeatTimer = xTaskGetTickCount(); + descriptionStart = 0; - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_B_LONG: - if (xTaskGetTickCount() - autoRepeatTimer - + autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) { - currentScreen++; - autoRepeatTimer = xTaskGetTickCount(); - descriptionStart = 0; + autoRepeatAcceleration += PRESS_ACCEL_STEP; + } + break; + case BUTTON_NONE: + default: + break; + } - autoRepeatAcceleration += PRESS_ACCEL_STEP; - } - break; - case BUTTON_NONE: - default: - break; - } - - if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) - < PRESS_ACCEL_INTERVAL_MIN) { - autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - - PRESS_ACCEL_INTERVAL_MIN; - } - - if (lcdRefresh) { - lcd.refresh(); // update the LCD - osDelay(40); - lcdRefresh = false; - } - } + if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < + PRESS_ACCEL_INTERVAL_MIN) { + autoRepeatAcceleration = + PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; + } + if (lcdRefresh) { + OLED::refresh(); // update the LCD + osDelay(40); + lcdRefresh = false; + } + } } void enterSettingsMenu() { - gui_Menu(rootSettingsMenu); //Call the root menu - saveSettings(); + gui_Menu(rootSettingsMenu); // Call the root menu + saveSettings(); } diff --git a/workspace/TS100/src/hardware.c b/workspace/TS100/src/hardware.c index ce383790..d88566ea 100644 --- a/workspace/TS100/src/hardware.c +++ b/workspace/TS100/src/hardware.c @@ -5,8 +5,10 @@ * Author: Ben V. Brown */ -//These are all the functions for interacting with the hardware +// These are all the functions for interacting with the hardware #include "hardware.h" +#include "FreeRTos.h" +#include "stm32f1xx_hal.h" volatile uint16_t PWMSafetyTimer = 0; volatile int16_t CalibrationTempOffset = 0; uint16_t tipGainCalValue = 0; @@ -22,32 +24,30 @@ void setCalibrationOffset(int16_t offSet) { } uint16_t getHandleTemperature() { // We return the current handle temperature in X10 C - // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for example) - // STM32 = 4096 count @ 3.3V input -> But - // We oversample by 32/(2^2) = 8 times oversampling - // Therefore 32768 is the 3.3V input, so 0.201416015625 mV per count - // So we need to subtract an offset of 0.5V to center on 0C (2482*2 counts) + // TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for + // example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) = + // 8 times oversampling Therefore 32768 is the 3.3V input, so 0.1007080078125 + // mV per count So we need to subtract an offset of 0.5V to center on 0C + // (4964.8 counts) // - uint16_t result = getADC(0); - if (result < 4964) - return 0; - result -= 4964; //remove 0.5V offset - result /= 10; //convert to X10 C + int32_t result = getADC(0); + result -= 4965; // remove 0.5V offset + // 10mV per C + // 99.29 counts per Deg C above 0C + result *= 10; + result /= 993; return result; - } uint16_t tipMeasurementToC(uint16_t raw) { - //((Raw Tip-RawOffset) * calibrationgain) / 1000 = tip delta in CX10 // tip delta in CX10 + handleTemp in CX10 = tip absolute temp in CX10 - //Div answer by 10 to get final result + // Div answer by 10 to get final result uint32_t tipDelta = ((raw - CalibrationTempOffset) * tipGainCalValue) / 1000; tipDelta += getHandleTemperature(); return tipDelta / 10; - } uint16_t ctoTipMeasurement(uint16_t temp) { //[ (temp-handle/10) * 10000 ]/calibrationgain = tip raw delta @@ -59,37 +59,34 @@ uint16_t ctoTipMeasurement(uint16_t temp) { } uint16_t tipMeasurementToF(uint16_t raw) { - //Convert result from C to F + // Convert result from C to F return (tipMeasurementToC(raw) * 9) / 5 + 32; - } uint16_t ftoTipMeasurement(uint16_t temp) { -//Convert the temp back to C from F + // Convert the temp back to C from F return ctoTipMeasurement(((temp - 32) * 5) / 9); } -uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipInstantTemperature() { +uint16_t getTipInstantTemperature() { uint16_t sum; - sum = HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_1); - sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_2); - sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_3); - sum += HAL_ADCEx_InjectedGetValue(&hadc1, ADC_INJECTED_RANK_4); - sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_1); - sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_2); - sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_3); - sum += HAL_ADCEx_InjectedGetValue(&hadc2, ADC_INJECTED_RANK_4); - - return sum; // 8x over sample - + sum = hadc1.Instance->JDR1; + sum += hadc1.Instance->JDR2; + sum += hadc1.Instance->JDR3; + sum += hadc1.Instance->JDR4; + sum += hadc2.Instance->JDR1; + sum += hadc2.Instance->JDR2; + sum += hadc2.Instance->JDR3; + sum += hadc2.Instance->JDR4; + return sum; // 8x over sample } /* * Loopup table for the tip calibration values for * the gain of the tip's - * This can be found by line of best fit of TipRaw on X, and TipTemp-handle on Y. - * Then take the m term * 10000 + * This can be found by line of best fit of TipRaw on X, and TipTemp-handle on + * Y. Then take the m term * 10000 * */ uint16_t lookupTipDefaultCalValue(enum TipType tipID) { - +#ifdef MODEL_TS100 switch (tipID) { case TS_D24: return 141; @@ -103,16 +100,28 @@ uint16_t lookupTipDefaultCalValue(enum TipType tipID) { case TS_B2: return 133; default: - return 132; // make this the average of all + return 132; // make this the average of all break; } +#else + switch (tipID) { + case TS_D25: + return 154; + break; + case TS_B02: + return 154; + break; + default: + return 154; // make this the average of all + break; + } +#endif } -uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipRawTemp( - uint8_t instant) { +uint16_t getTipRawTemp(uint8_t instant) { static int64_t filterFP = 0; static uint16_t lastSample = 0; - const uint8_t filterBeta = 7; //higher values smooth out more, but reduce responsiveness + const uint8_t filterBeta = 7; // higher values smooth out more, but reduce responsiveness if (instant == 1) { uint16_t itemp = getTipInstantTemperature(); @@ -132,10 +141,10 @@ uint16_t __attribute__ ((long_call, section (".data.ramfuncs"))) getTipRawTemp( } } uint16_t getInputVoltageX10(uint16_t divisor) { - //ADC maximum is 32767 == 3.3V at input == 28.05V at VIN - //Therefore we can divide down from there - //Multiplying ADC max by 4 for additional calibration options, - //ideal term is 467 + // ADC maximum is 32767 == 3.3V at input == 28.05V at VIN + // Therefore we can divide down from there + // Multiplying ADC max by 4 for additional calibration options, + // ideal term is 467 #define BATTFILTERDEPTH 64 static uint8_t preFillneeded = 1; static uint32_t samples[BATTFILTERDEPTH]; @@ -157,27 +166,277 @@ uint16_t getInputVoltageX10(uint16_t divisor) { preFillneeded = 1; return sum * 4 / divisor; } +#ifdef MODEL_TS80 +uint8_t QCMode = 0; +void seekQC(int16_t Vx10) { + if (QCMode <= 1) + return; // NOT connected to a QC Charger + if (Vx10 < 50) + return; + // Seek the QC to the Voltage given if this adapter supports continuous mode + // try and step towards the wanted value + + // 1. Measure current voltage + int16_t vStart = getInputVoltageX10(195); + int difference = Vx10 - vStart; + + // 2. calculate ideal steps (0.2V changes) + + int steps = difference / 2; + if (QCMode == 3) { + while (steps < 0) { + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + vTaskDelay(3); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + vTaskDelay(3); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); + HAL_IWDG_Refresh(&hiwdg); + vTaskDelay(3); + steps++; + } + while (steps > 0) { + // step once up + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + vTaskDelay(3); + + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); + vTaskDelay(3); + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_IWDG_Refresh(&hiwdg); + vTaskDelay(3); + steps--; + } + } + // Re-measure + /* Disabled due to nothing to test and code space of around 1k*/ +#ifdef QC2_ROUND_DOWN + steps = vStart - getInputVoltageX10(195); + if (steps < 0) steps = -steps; + if (steps > (difference / 2)) { + // No continuous mode, so QC2 + QCMode = 2; + // Goto nearest + if (Vx10 > 10.5) { + // request 12V + // D- = 0.6V, D+ = 0.6V + // Clamp PB3 + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull down D+ + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + + } else { + // request 9V + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + } + } +#endif +} + +// Must be called after FreeRToS Starts +void startQC() { + // Pre check that the input could be >5V already, and if so, dont both + // negotiating as someone is feeding in hv + uint16_t vin = getInputVoltageX10(205); + if (vin > 150) + return;// Over voltage + if (vin > 100) { + QCMode = 1; // ALready at ~12V + return; + } + GPIO_InitTypeDef GPIO_InitStruct; + + // Tries to negotiate QC for 9V + // This is a multiple step process. + // 1. Set around 0.6V on D+ for 1.25 Seconds or so + // 2. After this It should un-short D+->D- and instead add a 20k pulldown on + // D- + // 3. Now set D+ to 3.3V and D- to 0.6V to request 9V + // OR both at 0.6V for 12V request (if the adapter can do it). + // If 12V is implimented then should fallback to 9V after validation + // Step 1. We want to pull D+ to 0.6V + // Pull PB3 donwn to ground + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+ + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + GPIO_InitStruct.Pin = GPIO_PIN_3; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET);// pull low to put 0.6V on D+ + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14 | GPIO_PIN_13; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + // Delay 1.25 seconds + uint8_t enteredQC = 0; + for (uint16_t i = 0; i < 130 && enteredQC == 0; i++) { + // HAL_Delay(10); + vTaskDelay(1); + HAL_IWDG_Refresh(&hiwdg); + } + // Check if D- is low to spot a QC charger + if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET) + enteredQC = 1; + if (enteredQC) { + // We have a QC capable charger + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_8; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); + HAL_IWDG_Refresh(&hiwdg); + + // Wait for frontend ADC to stabilise + QCMode = 4; + for (uint8_t i = 0; i < 10; i++) { + if (getInputVoltageX10(195) > 80) { + // yay we have at least QC2.0 or QC3.0 + QCMode = 3;// We have at least QC2, pray for 3 + HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); + return; + } + vTaskDelay(10); // 100mS + } + QCMode = 0; + // No QC / not working to us + + } else { + // no QC + } +} +// Get tip resistance in milliohms +uint32_t calculateTipR(uint8_t useFilter) { + // We inject a small current into the front end of the iron, + // By measuring the Vdrop over the tip we can calculate the resistance + // Turn PA0 into an output and drive high to inject (3.3V-0.6)/(6K8+Rtip) + // current PA0->Diode -> 6K8 -> Tip -> GND So the op-amp will amplify the + // small signal across the tip and convert this into an easily read voltage + GPIO_InitTypeDef GPIO_InitStruct; + GPIO_InitStruct.Pin = GPIO_PIN_0; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);// Set low first + setTipPWM(0); + vTaskDelay(1); + uint32_t offReading = getTipInstantTemperature(); + for (uint8_t i = 0; i < 24; i++) { + if (useFilter == 0) { + vTaskDelay(1); // delay to allow it too stabilize + offReading += getTipInstantTemperature(); + } else { + offReading += getTipRawTemp(0); + } + } + + // Turn on + HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);// Set low first + vTaskDelay(1);// delay to allow it too stabilize + uint32_t onReading = getTipInstantTemperature(); + for (uint8_t i = 0; i < 24; i++) { + if (useFilter == 0) { + vTaskDelay(1); // delay to allow it too stabilize + onReading += getTipInstantTemperature(); + } else { + onReading += getTipRawTemp(0); + } + } + + uint32_t difference = onReading - offReading; + // V = IR, therefore I = V/R + // We can divide this reading by a known "gain" to get the resulting + // resistance This was determined emperically This tip is 4.688444162 ohms, + // 4688 milliohms (Measured using 4 terminal measurement) 25x oversampling + // reads this as around 47490 Almost perfectly 10x the milliohms value This + // will drift massively with tip temp However we really only need 10x ohms + return (difference / 10) + 1;// ceil +} +static unsigned int sqrt32(unsigned long n) { + unsigned int c = 0x8000; + unsigned int g = 0x8000; + + for (;;) { + if (g * g > n) + g ^= c; + c >>= 1; + if (c == 0) + return g; + g |= c; + } +} +int16_t calculateMaxVoltage(uint8_t useFilter, uint8_t useHP) { + // This measures the tip resistance, then it calculates the appropriate + // voltage To stay under ~18W. Mosfet is "9A", so no issues there + // QC3.0 supports up to 18W, which is 2A @9V and 1.5A @12V + uint32_t milliOhms = calculateTipR(useFilter); + // Check no tip + if (milliOhms > 10000) + return -1; + // + // V = sqrt(18W*R) + // Convert this to sqrt(18W)*sqrt(milli ohms)*sqrt(1/1000) + + uint32_t Vx = sqrt32(milliOhms); + if (useHP) + Vx *= 1549;//sqrt(24)*sqrt(1/1000) + else + Vx *= 1342;// sqrt(18) * sqrt(1/1000) + + // Round to nearest 200mV, + // So divide by 100 to start, to get in Vxx + Vx /= 100; + if (Vx % 10 >= 5) + Vx += 10; + Vx /= 10; + // Round to nearest increment of 2 + if (Vx % 2 == 1) + Vx++; + return Vx; +} + +#endif volatile uint32_t pendingPWM = 0; uint8_t getTipPWM() { return pendingPWM; } -void __attribute__ ((long_call, section (".data.ramfuncs"))) setTipPWM(uint8_t pulse) { - PWMSafetyTimer = 2; //This is decremented in the handler for PWM so that the tip pwm is disabled if the PID task is not scheduled often enough. +void setTipPWM(uint8_t pulse) { + PWMSafetyTimer = 2; // This is decremented in the handler for PWM so that the tip pwm is + // disabled if the PID task is not scheduled often enough. if (pulse > 100) pulse = 100; pendingPWM = pulse; } -//These are called by the HAL after the corresponding events from the system timers. +// These are called by the HAL after the corresponding events from the system +// timers. -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PeriodElapsedCallback( - TIM_HandleTypeDef *htim) { - //Period has elapsed +void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { + // Period has elapsed if (htim->Instance == TIM2) { - //we want to turn on the output again - PWMSafetyTimer--; //We decrement this safety value so that lockups in the scheduler will not cause the PWM to become locked in an active driving state. - //While we could assume this could never happen, its a small price for increased safety + // we want to turn on the output again + PWMSafetyTimer--; // We decrement this safety value so that lockups in the + // scheduler will not cause the PWM to become locked in an + // active driving state. + // While we could assume this could never happen, its a small price for + // increased safety htim2.Instance->CCR4 = pendingPWM; if (htim2.Instance->CCR4 && PWMSafetyTimer) { htim3.Instance->CCR1 = 50; @@ -192,15 +451,12 @@ void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PeriodElaps } } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_TIM_PWM_PulseFinishedCallback( - TIM_HandleTypeDef *htim) { +void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM2) { - //This was a when the PWM for the output has timed out + // This was a when the PWM for the output has timed out if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) { HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1); htim3.Instance->CCR1 = 0; - } } } - diff --git a/workspace/TS100/src/main.cpp b/workspace/TS100/src/main.cpp index 221ff5b4..ac8a2033 100644 --- a/workspace/TS100/src/main.cpp +++ b/workspace/TS100/src/main.cpp @@ -1,29 +1,22 @@ // By Ben V. Brown - V2.0 of the TS100 firmware #include +#include #include -#include "OLED.hpp" +#include "LIS2DH12.hpp" #include "Settings.h" #include "Translation.h" #include "cmsis_os.h" #include "stdlib.h" #include "stm32f1xx_hal.h" #include "string.h" -#include "LIS2DH12.hpp" -#include -#include "FRToSI2C.hpp" #define ACCELDEBUG 0 -// C++ objects -FRToSI2C i2cDev(&hi2c1); -OLED lcd(&i2cDev); -MMA8652FC accel(&i2cDev); -LIS2DH12 accel2(&i2cDev); uint8_t PCBVersion = 0; // File local variables uint16_t currentlyActiveTemperatureTarget = 0; uint32_t lastMovementTime = 0; uint32_t lastButtonTime = 0; - +int16_t idealQCVoltage = 0; // FreeRTOS variables osThreadId GUITaskHandle; osThreadId PIDTaskHandle; @@ -43,45 +36,47 @@ int main(void) { HAL_Init(); Setup_HAL(); // Setup all the HAL objects HAL_IWDG_Refresh(&hiwdg); - setTipPWM(0); - lcd.initialize(); // start up the LCD - lcd.setFont(0); // default to bigger font - //Testing for new weird board version + setTipPWM(0); // force tip off + FRToSI2C::init(&hi2c1); + OLED::initialize(); // start up the LCD + OLED::setFont(0); // default to bigger font + // Testing for which accelerometer is mounted uint8_t buffer[1]; HAL_IWDG_Refresh(&hiwdg); if (HAL_I2C_Mem_Read(&hi2c1, 29 << 1, 0x0F, I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK) { PCBVersion = 1; - accel.initalize(); // this sets up the I2C registers and loads up the default - // settings + MMA8652FC::initalize(); // this sets up the I2C registers } else if (HAL_I2C_Mem_Read(&hi2c1, 25 << 1, 0x0F, I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK) { PCBVersion = 2; - //Setup the ST Accelerometer - accel2.initalize(); //startup the accelerometer + // Setup the ST Accelerometer + LIS2DH12::initalize(); // startup the accelerometer } else { PCBVersion = 3; systemSettings.SleepTime = 0; - systemSettings.ShutdownTime = 0; //No accel -> disable sleep + systemSettings.ShutdownTime = 0; // No accel -> disable sleep systemSettings.sensitivity = 0; + saveSettings(); } HAL_IWDG_Refresh(&hiwdg); restoreSettings(); // load the settings from flash setCalibrationOffset(systemSettings.CalibrationOffset); - setTipType((enum TipType)systemSettings.tipType, systemSettings.customTipGain); //apply tip type selection + setTipType((enum TipType) systemSettings.tipType, + systemSettings.customTipGain); // apply tip type selection HAL_IWDG_Refresh(&hiwdg); /* Create the thread(s) */ /* definition and creation of GUITask */ - osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 768); //3k + osThreadDef(GUITask, startGUITask, osPriorityBelowNormal, 0, 768); // 3k GUITaskHandle = osThreadCreate(osThread(GUITask), NULL); /* definition and creation of PIDTask */ - osThreadDef(PIDTask, startPIDTask, osPriorityRealtime, 0, 512); //2k + osThreadDef(PIDTask, startPIDTask, osPriorityRealtime, 0, 512); // 2k PIDTaskHandle = osThreadCreate(osThread(PIDTask), NULL); - if (PCBVersion != 3) { + if (PCBVersion < 3) { /* definition and creation of MOVTask */ - osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 512); //2k + osThreadDef(MOVTask, startMOVTask, osPriorityNormal, 0, 512); // 2k MOVTaskHandle = osThreadCreate(osThread(MOVTask), NULL); } @@ -93,14 +88,15 @@ int main(void) { } } void printVoltage() { - lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2); - lcd.drawChar('.'); - lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2); + OLED::drawChar('.'); + OLED::printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1); } void GUIDelay() { - //Called in all UI looping tasks, - //This limits the re-draw rate to the LCD and also lets the DMA run - //As the gui task can very easily fill this bus with transactions, which will prevent the movement detection from running + // Called in all UI looping tasks, + // This limits the re-draw rate to the LCD and also lets the DMA run + // As the gui task can very easily fill this bus with transactions, which will + // prevent the movement detection from running osDelay(50); } void gui_drawTipTemp(bool symbol) { @@ -111,16 +107,13 @@ void gui_drawTipTemp(bool symbol) { Temp = tipMeasurementToF(Temp); else Temp = tipMeasurementToC(Temp); - //[Disabled 24/11/2017] Round if nearby - // if (abs(Temp - systemSettings.SolderingTemp) < 3) - // Temp = systemSettings.SolderingTemp; - lcd.printNumber(Temp, 3); // Draw the tip temp out finally + OLED::printNumber(Temp, 3); // Draw the tip temp out finally if (symbol) { if (systemSettings.temperatureInF) - lcd.print("F"); + OLED::print("F"); else - lcd.print("C"); + OLED::print("C"); } } ButtonState getButtonState() { @@ -167,7 +160,14 @@ ButtonState getButtonState() { ButtonState retVal = BUTTON_NONE; if (currentState) { // User has pressed a button down (nothing done on down) - + if (currentState != previousState) { + // There has been a change in the button states + // If there is a rising edge on one of the buttons from double press we + // want to mask that out As users are having issues with not release + // both at once + if (previousState == 0x03) + currentState = 0x03; + } } else { // User has released buttons // If they previously had the buttons down we want to check if they were < @@ -191,78 +191,103 @@ ButtonState getButtonState() { return BUTTON_NONE; } - void waitForButtonPress() { +void waitForButtonPress() { // we are just lazy and sleep until user confirms button press // This also eats the button press event! ButtonState buttons = getButtonState(); while (buttons) { buttons = getButtonState(); - lcd.refresh(); + GUIDelay(); GUIDelay(); } while (!buttons) { buttons = getButtonState(); - lcd.refresh(); + GUIDelay(); GUIDelay(); } } void waitForButtonPressOrTimeout(uint32_t timeout) { timeout += xTaskGetTickCount(); - // Make timeout our exit value - for (;;) { - ButtonState buttons = getButtonState(); - if (buttons) - return; + // calculate the exit point + + ButtonState buttons = getButtonState(); + while (buttons) { + buttons = getButtonState(); + GUIDelay(); if (xTaskGetTickCount() > timeout) return; + } + while (!buttons) { + buttons = getButtonState(); GUIDelay(); + if (xTaskGetTickCount() > timeout) + return; } } - +#ifdef MODEL_TS100 // returns true if undervoltage has occured static bool checkVoltageForExit() { uint16_t v = getInputVoltageX10(systemSettings.voltageDiv); if ((v < lookupVoltageLevel(systemSettings.cutoutSetting))) { - lcd.clearScreen(); - lcd.setCursor(0, 0); + OLED::clearScreen(); + OLED::setCursor(0, 0); if (systemSettings.detailedSoldering) { - lcd.setFont(1); - lcd.print(UndervoltageString); - lcd.setCursor(0, 8); - lcd.print(InputVoltageString); + OLED::setFont(1); + OLED::print(UndervoltageString); + OLED::setCursor(0, 8); + OLED::print(InputVoltageString); printVoltage(); - lcd.print("V"); + OLED::print("V"); } else { - lcd.setFont(0); - lcd.print(UVLOWarningString); + OLED::setFont(0); + OLED::print(UVLOWarningString); } - lcd.refresh(); + OLED::refresh(); currentlyActiveTemperatureTarget = 0; waitForButtonPress(); return true; } return false; } +#endif static void gui_drawBatteryIcon() { +#ifdef MODEL_TS100 if (systemSettings.cutoutSetting) { // User is on a lithium battery // we need to calculate which of the 10 levels they are on uint8_t cellCount = systemSettings.cutoutSetting + 2; - uint16_t cellV = getInputVoltageX10(systemSettings.voltageDiv) - / cellCount; + uint16_t cellV = getInputVoltageX10(systemSettings.voltageDiv) / cellCount; // Should give us approx cell voltage X10 // Range is 42 -> 33 = 9 steps therefore we will use battery 1-10 - if (cellV < 33) - cellV = 33; - cellV -= 33; // Should leave us a number of 0-9 - if (cellV > 9) - cellV = 9; - lcd.drawBattery(cellV + 1); + if (cellV < 33) cellV = 33; + cellV -= 33;// Should leave us a number of 0-9 + if (cellV > 9) cellV = 9; + OLED::drawBattery(cellV + 1); } else - lcd.drawSymbol(15); // Draw the DC Logo + OLED::drawSymbol(15); // Draw the DC Logo +#else + // On TS80 we replace this symbol with the voltage we are operating on + // If <9V then show single digit, if not show duals + uint8_t V = getInputVoltageX10(systemSettings.voltageDiv); + if (V % 10 >= 5) + V = V / 10 + 1; // round up + else + V = V / 10; + if (V >= 10) { + int16_t xPos = OLED::getCursorX(); + OLED::setFont(1); + OLED::printNumber(1, 1); + OLED::setCursor(xPos, 8); + OLED::printNumber(V % 10, 1); + + OLED::setFont(0); + } else { + OLED::printNumber(V, 1); + } +#endif } static void gui_solderingTempAdjust() { uint32_t lastChange = xTaskGetTickCount(); @@ -270,9 +295,9 @@ static void gui_solderingTempAdjust() { uint32_t autoRepeatTimer = 0; uint8_t autoRepeatAcceleration = 0; for (;;) { - lcd.setCursor(0, 0); - lcd.clearScreen(); - lcd.setFont(0); + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); ButtonState buttons = getButtonState(); if (buttons) lastChange = xTaskGetTickCount(); @@ -284,35 +309,35 @@ static void gui_solderingTempAdjust() { // exit return; break; - case BUTTON_B_LONG: - if (xTaskGetTickCount() - autoRepeatTimer - + autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) { + case BUTTON_F_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { systemSettings.SolderingTemp -= 10; // sub 10 autoRepeatTimer = xTaskGetTickCount(); autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; - case BUTTON_F_LONG: - if (xTaskGetTickCount() - autoRepeatTimer - + autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) { + case BUTTON_B_LONG: + if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > + PRESS_ACCEL_INTERVAL_MAX) { systemSettings.SolderingTemp += 10; autoRepeatTimer = xTaskGetTickCount(); autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; - case BUTTON_F_SHORT: + case BUTTON_B_SHORT: systemSettings.SolderingTemp += 10; // add 10 break; - case BUTTON_B_SHORT: + case BUTTON_F_SHORT: systemSettings.SolderingTemp -= 10; // sub 10 break; default: break; } - if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) - < PRESS_ACCEL_INTERVAL_MIN) { - autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - - PRESS_ACCEL_INTERVAL_MIN; + if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < + PRESS_ACCEL_INTERVAL_MIN) { + autoRepeatAcceleration = + PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; } // constrain between 50-450 C if (systemSettings.temperatureInF) { @@ -330,23 +355,23 @@ static void gui_solderingTempAdjust() { if (xTaskGetTickCount() - lastChange > 200) return; // exit if user just doesn't press anything for a bit - if (lcd.getRotation()) - lcd.drawChar('-'); + if (OLED::getRotation()) + OLED::drawChar('-'); else - lcd.drawChar('+'); + OLED::drawChar('+'); - lcd.drawChar(' '); - lcd.printNumber(systemSettings.SolderingTemp, 3); + OLED::drawChar(' '); + OLED::printNumber(systemSettings.SolderingTemp, 3); if (systemSettings.temperatureInF) - lcd.drawSymbol(0); + OLED::drawSymbol(0); else - lcd.drawSymbol(1); - lcd.drawChar(' '); - if (lcd.getRotation()) - lcd.drawChar('+'); + OLED::drawSymbol(1); + OLED::drawChar(' '); + if (OLED::getRotation()) + OLED::drawChar('+'); else - lcd.drawChar('-'); - lcd.refresh(); + OLED::drawChar('-'); + OLED::refresh(); GUIDelay(); } } @@ -367,9 +392,9 @@ static int gui_SolderingSleepingMode() { if ((xTaskGetTickCount() - lastMovementTime < 100) || (xTaskGetTickCount() - lastButtonTime < 100)) return 0; // user moved or pressed a button, go back to soldering - if (checkVoltageForExit()) - return 1; // return non-zero on error - +#ifdef MODEL_TS100 + if (checkVoltageForExit()) return 1; // return non-zero on error +#endif if (systemSettings.temperatureInF) { currentlyActiveTemperatureTarget = ftoTipMeasurement( min(systemSettings.SleepTemp, @@ -386,30 +411,30 @@ static int gui_SolderingSleepingMode() { else tipTemp = tipMeasurementToC(getTipRawTemp(0)); - lcd.clearScreen(); - lcd.setCursor(0, 0); + OLED::clearScreen(); + OLED::setCursor(0, 0); if (systemSettings.detailedSoldering) { - lcd.setFont(1); - lcd.print(SleepingAdvancedString); - lcd.setCursor(0, 8); - lcd.print(SleepingTipAdvancedString); - lcd.printNumber(tipTemp, 3); + OLED::setFont(1); + OLED::print(SleepingAdvancedString); + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); + OLED::printNumber(tipTemp, 3); if (systemSettings.temperatureInF) - lcd.print("F"); + OLED::print("F"); else - lcd.print("C"); + OLED::print("C"); - lcd.print(" "); + OLED::print(" "); printVoltage(); - lcd.drawChar('V'); + OLED::drawChar('V'); } else { - lcd.setFont(0); - lcd.print(SleepingSimpleString); - lcd.printNumber(tipTemp, 3); + OLED::setFont(0); + OLED::print(SleepingSimpleString); + OLED::printNumber(tipTemp, 3); if (systemSettings.temperatureInF) - lcd.drawSymbol(0); + OLED::drawSymbol(0); else - lcd.drawSymbol(1); + OLED::drawSymbol(1); } if (systemSettings.ShutdownTime) // only allow shutdown exit if time > 0 if (lastMovementTime) @@ -419,7 +444,7 @@ static int gui_SolderingSleepingMode() { currentlyActiveTemperatureTarget = 0; return 1; // we want to exit soldering mode } - lcd.refresh(); + OLED::refresh(); GUIDelay(); } return 0; @@ -435,15 +460,15 @@ static void display_countdown(int sleepThres) { lastMovementTime : lastButtonTime; int downCount = sleepThres - xTaskGetTickCount() + lastEventTime; if (downCount > 9900) { - lcd.printNumber(downCount / 6000 + 1, 2); - lcd.print("M"); + OLED::printNumber(downCount / 6000 + 1, 2); + OLED::print("M"); } else { - lcd.printNumber(downCount / 100 + 1, 2); - lcd.print("S"); + OLED::printNumber(downCount / 100 + 1, 2); + OLED::print("S"); } } -static void gui_solderingMode() { +static void gui_solderingMode(uint8_t jumpToSleep) { /* * * Soldering (gui_solderingMode) * -> Main loop where we draw temp, and animations @@ -497,67 +522,72 @@ static void gui_solderingMode() { break; } // else we update the screen information - lcd.setCursor(0, 0); - lcd.clearScreen(); - lcd.setFont(0); + OLED::setCursor(0, 0); + OLED::clearScreen(); + OLED::setFont(0); if (tipTemp > 32752) { - lcd.print(BadTipString); - lcd.refresh(); + OLED::print(BadTipString); + OLED::refresh(); currentlyActiveTemperatureTarget = 0; waitForButtonPress(); return; } else { if (systemSettings.detailedSoldering) { - lcd.setFont(1);/* - lcd.print(SolderingAdvancedPowerPrompt); //Power: - lcd.printNumber(getTipPWM(), 3); - lcd.print("%");*/ - lcd.printNumber(getTipRawTemp(0), 6); + OLED::setFont(1); + OLED::print(SolderingAdvancedPowerPrompt); // Power: + OLED::printNumber(getTipPWM(), 3); + OLED::print("%"); + // OLED::printNumber(getTipRawTemp(0), 6); if (systemSettings.sensitivity && systemSettings.SleepTime) { - lcd.print(" "); + OLED::print(" "); display_countdown(sleepThres); } - lcd.setCursor(0, 8); - lcd.print(SleepingTipAdvancedString); + OLED::setCursor(0, 8); + OLED::print(SleepingTipAdvancedString); gui_drawTipTemp(true); - lcd.print(" "); + OLED::print(" "); printVoltage(); - lcd.drawChar('V'); + OLED::drawChar('V'); } else { - // We switch the layout direction depending on the orientation of the lcd. - if (lcd.getRotation()) { + // We switch the layout direction depending on the orientation of the + // OLED:: + if (OLED::getRotation()) { // battery gui_drawBatteryIcon(); - lcd.drawChar(' '); // Space out gap between battery <-> temp + OLED::drawChar(' '); // Space out gap between battery <-> temp gui_drawTipTemp(true); // Draw current tip temp - // We draw boost arrow if boosting, or else gap temp <-> heat indicator + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator if (boostModeOn) - lcd.drawSymbol(2); + OLED::drawSymbol(2); else - lcd.drawChar(' '); + OLED::drawChar(' '); // Draw heating/cooling symbols - lcd.drawHeatSymbol(getTipPWM()); + OLED::drawHeatSymbol(getTipPWM()); } else { // Draw heating/cooling symbols - lcd.drawHeatSymbol(getTipPWM()); - // We draw boost arrow if boosting, or else gap temp <-> heat indicator + OLED::drawHeatSymbol(getTipPWM()); + // We draw boost arrow if boosting, or else gap temp <-> heat + // indicator if (boostModeOn) - lcd.drawSymbol(2); + OLED::drawSymbol(2); else - lcd.drawChar(' '); + OLED::drawChar(' '); gui_drawTipTemp(true); // Draw current tip temp - lcd.drawChar(' '); // Space out gap between battery <-> temp + OLED::drawChar(' '); // Space out gap between battery <-> temp gui_drawBatteryIcon(); } } } + OLED::refresh(); + // Update the setpoints for the temperature if (boostModeOn) { if (systemSettings.temperatureInF) @@ -576,13 +606,25 @@ static void gui_solderingMode() { systemSettings.SolderingTemp); } +#ifdef MODEL_TS100 // Undervoltage test if (checkVoltageForExit()) { lastButtonTime = xTaskGetTickCount(); return; } - - lcd.refresh(); +#else + // on the TS80 we only want to check for over voltage to prevent tip damage + if (getInputVoltageX10(systemSettings.voltageDiv) > 150) { + lastButtonTime = xTaskGetTickCount(); + return; // Over voltage + } +#endif + if (jumpToSleep) { + if (gui_SolderingSleepingMode()) { + lastButtonTime = xTaskGetTickCount(); + return; // If the function returns non-0 then exit + } + } if (systemSettings.sensitivity && systemSettings.SleepTime) if (xTaskGetTickCount() - lastMovementTime > sleepThres && xTaskGetTickCount() - lastButtonTime > sleepThres) { @@ -596,61 +638,67 @@ static void gui_solderingMode() { } static const char *HEADERS[] = { -__DATE__, "Heap: ", "HWMG: ", "HWMP: ", "HWMM: ", "Time: ", "Move: ", "Rtip: ", - "Ctip: ", "Vin :", "THan: " }; +__DATE__, "Heap: ", "HWMG: ", "HWMP: ", "HWMM: ", "Time: ", "Move: ", "RTip: ", + "CTip: ", "Vin :", "THan: ", "Model: " }; void showVersion(void) { uint8_t screen = 0; ButtonState b; for (;;) { - lcd.clearScreen(); // Ensure the buffer starts clean - lcd.setCursor(0, 0); // Position the cursor at the 0,0 (top left) - lcd.setFont(1); // small font - lcd.print((char *) "V2.05 PCB"); // Print version number - lcd.printNumber(PCBVersion, 1); //Print PCB ID number - lcd.setCursor(0, 8); // second line - lcd.print(HEADERS[screen]); + OLED::clearScreen(); // Ensure the buffer starts clean + OLED::setCursor(0, 0); // Position the cursor at the 0,0 (top left) + OLED::setFont(1); // small font +#ifdef MODEL_TS100 + OLED::print((char *)"V2.06 TS100"); // Print version number +#else + OLED::print((char *) "V2.06 TS80"); // Print version number +#endif + OLED::setCursor(0, 8); // second line + OLED::print(HEADERS[screen]); switch (screen) { case 1: - lcd.printNumber(xPortGetFreeHeapSize(), 5); + OLED::printNumber(xPortGetFreeHeapSize(), 5); break; case 2: - lcd.printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); + OLED::printNumber(uxTaskGetStackHighWaterMark(GUITaskHandle), 5); break; case 3: - lcd.printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); + OLED::printNumber(uxTaskGetStackHighWaterMark(PIDTaskHandle), 5); break; case 4: - lcd.printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); + OLED::printNumber(uxTaskGetStackHighWaterMark(MOVTaskHandle), 5); break; case 5: - lcd.printNumber(xTaskGetTickCount() / 100, 5); + OLED::printNumber(xTaskGetTickCount() / 100, 5); break; case 6: - lcd.printNumber(lastMovementTime / 100, 5); + OLED::printNumber(lastMovementTime / 100, 5); break; case 7: - lcd.printNumber(getTipRawTemp(0), 6); + OLED::printNumber(getTipRawTemp(0), 6); break; case 8: - lcd.printNumber(tipMeasurementToC(getTipRawTemp(0)), 5); + OLED::printNumber(tipMeasurementToC(getTipRawTemp(0)), 5); break; case 9: printVoltage(); break; case 10: - lcd.printNumber(getHandleTemperature(), 3); + OLED::printNumber(getHandleTemperature(), 3); + case 11: + OLED::printNumber(PCBVersion, 1); // Print PCB ID number + break; default: break; } - lcd.refresh(); + OLED::refresh(); b = getButtonState(); if (b == BUTTON_B_SHORT) return; else if (b == BUTTON_F_SHORT) { screen++; - screen = screen % 11; + screen = screen % 12; } GUIDelay(); } @@ -658,26 +706,28 @@ void showVersion(void) { /* StartGUITask function */ void startGUITask(void const *argument __unused) { - i2cDev.FRToSInit(); + FRToSI2C::FRToSInit(); uint8_t tempWarningState = 0; bool buttonLockout = false; bool tempOnDisplay = false; - getTipRawTemp(2); //reset filter - lcd.setRotation(systemSettings.OrientationMode & 1); + getTipRawTemp(2); // reset filter + OLED::setRotation(systemSettings.OrientationMode & 1); uint32_t ticks = xTaskGetTickCount(); - ticks += 400; //4 seconds from now + ticks += 400; // 4 seconds from now while (xTaskGetTickCount() < ticks) { if (showBootLogoIfavailable() == false) ticks = xTaskGetTickCount(); ButtonState buttons = getButtonState(); if (buttons) - ticks = xTaskGetTickCount(); //make timeout now so we will exit + ticks = xTaskGetTickCount(); // make timeout now so we will exit GUIDelay(); } if (systemSettings.autoStartMode) { // jump directly to the autostart mode if (systemSettings.autoStartMode == 1) - gui_solderingMode(); + gui_solderingMode(0); + if (systemSettings.autoStartMode == 2) + gui_solderingMode(1); } #if ACCELDEBUG @@ -705,7 +755,8 @@ void startGUITask(void const *argument __unused) { break; case BUTTON_BOTH: // Not used yet - //In multi-language this might be used to reset language on a long hold or some such + // In multi-language this might be used to reset language on a long hold + // or some such break; case BUTTON_B_LONG: @@ -717,15 +768,21 @@ void startGUITask(void const *argument __unused) { saveSettings(); break; case BUTTON_F_SHORT: - lcd.setFont(0); - lcd.displayOnOff(true); // turn lcd on - gui_solderingMode(); // enter soldering mode + OLED::setFont(0); + OLED::displayOnOff(true); // turn lcd on +#ifdef MODEL_TS80 + if (idealQCVoltage < 90) + idealQCVoltage = calculateMaxVoltage(1, + systemSettings.cutoutSetting); // 1 means use filtered values rather than do its own + seekQC(idealQCVoltage); +#endif + gui_solderingMode(0); // enter soldering mode buttonLockout = true; break; case BUTTON_B_SHORT: - lcd.setFont(0); - lcd.displayOnOff(true); // turn lcd on - enterSettingsMenu(); // enter the settings menu + OLED::setFont(0); + OLED::displayOnOff(true); // turn lcd on + enterSettingsMenu(); // enter the settings menu saveSettings(); buttonLockout = true; setCalibrationOffset(systemSettings.CalibrationOffset); // ensure cal offset is applied @@ -736,55 +793,58 @@ void startGUITask(void const *argument __unused) { currentlyActiveTemperatureTarget = 0; // ensure tip is off - uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(1)); //This forces a faster update rate on the filtering + uint16_t tipTemp = tipMeasurementToC(getTipRawTemp(1)); // This forces a faster update rate on the filtering if (tipTemp < 50) { - if (systemSettings.sensitivity) { - if ((xTaskGetTickCount() - lastMovementTime) > 6000 && (xTaskGetTickCount() - lastButtonTime) > 6000) { - lcd.displayOnOff(false); // turn lcd off when no movement + OLED::displayOnOff(false); // turn lcd off when no movement } else - lcd.displayOnOff(true); // turn lcd on + OLED::displayOnOff(true); // turn lcd on } else - lcd.displayOnOff(true); // turn lcd on - disabled motion sleep + OLED::displayOnOff(true); // turn lcd on - disabled motion sleep } else - lcd.displayOnOff(true); // turn lcd on when temp > 50C + OLED::displayOnOff(true); // turn lcd on when temp > 50C if (tipTemp > 600) tipTemp = 0; // Clear the lcd buffer - lcd.clearScreen(); - lcd.setCursor(0, 0); + OLED::clearScreen(); + OLED::setCursor(0, 0); if (systemSettings.detailedIDLE) { - lcd.setFont(1); + OLED::setFont(1); if (tipTemp > 470) { - lcd.print(TipDisconnectedString); + OLED::print(TipDisconnectedString); } else { - lcd.print(IdleTipString); + OLED::print(IdleTipString); if (systemSettings.temperatureInF) - lcd.printNumber(tipMeasurementToF(getTipRawTemp(0)), 3); + OLED::printNumber(tipMeasurementToF(getTipRawTemp(0)), 3); else - lcd.printNumber(tipMeasurementToC(getTipRawTemp(0)), 3); - lcd.print(IdleSetString); - lcd.printNumber(systemSettings.SolderingTemp, 3); + OLED::printNumber(tipMeasurementToC(getTipRawTemp(0)), 3); + OLED::print(IdleSetString); + OLED::printNumber(systemSettings.SolderingTemp, 3); } - lcd.setCursor(0, 8); - lcd.print(InputVoltageString); + OLED::setCursor(0, 8); + + OLED::print(InputVoltageString); printVoltage(); - lcd.print("V"); } else { - lcd.setFont(0); - if (lcd.getRotation()) { - lcd.drawArea(12, 0, 84, 16, idleScreenBG); - lcd.setCursor(0, 0); + OLED::setFont(0); +#ifdef MODEL_TS80 + if (!OLED::getRotation()) { +#else + if (OLED::getRotation()) { +#endif + OLED::drawArea(12, 0, 84, 16, idleScreenBG); + OLED::setCursor(0, 0); gui_drawBatteryIcon(); } else { - lcd.drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up on right side of screen - lcd.setCursor(84, 0); + OLED::drawArea(0, 0, 84, 16, idleScreenBGF); // Needs to be flipped so button ends up + // on right side of screen + OLED::setCursor(84, 0); gui_drawBatteryIcon(); } if (tipTemp > 55) @@ -792,32 +852,36 @@ void startGUITask(void const *argument __unused) { else if (tipTemp < 45) tempOnDisplay = false; if (tempOnDisplay) { - //draw temp over the start soldering button - //Location changes on screen rotation - if (lcd.getRotation()) { + // draw temp over the start soldering button + // Location changes on screen rotation +#ifdef MODEL_TS80 + if (!OLED::getRotation()) { +#else + if (OLED::getRotation()) { +#endif // in right handed mode we want to draw over the first part - lcd.fillArea(55, 0, 41, 16, 0); //clear the area for the temp - lcd.setCursor(56, 0); + OLED::fillArea(55, 0, 41, 16, 0); // clear the area for the temp + OLED::setCursor(56, 0); } else { - lcd.fillArea(0, 0, 41, 16, 0); //clear the area - lcd.setCursor(0, 0); + OLED::fillArea(0, 0, 41, 16, 0); // clear the area + OLED::setCursor(0, 0); } - //draw in the temp - lcd.setFont(0); //big font + // draw in the temp + OLED::setFont(0); // big font if (!(systemSettings.coolingTempBlink && (xTaskGetTickCount() % 50 < 25))) - gui_drawTipTemp(false); // draw in the temp + gui_drawTipTemp(false); // draw in the temp } } - lcd.refresh(); + OLED::refresh(); GUIDelay(); } } /* StartPIDTask function */ -void __attribute__ ((long_call, section (".data.ramfuncs"))) startPIDTask(void const *argument __unused) { +void startPIDTask(void const *argument __unused) { /* * We take the current tip temperature & evaluate the next step for the tip * control PWM @@ -828,27 +892,48 @@ void __attribute__ ((long_call, section (".data.ramfuncs"))) startPIDTask(void c * struct * */ - setTipPWM(0); // disable the output driver if the output is set to be off - osDelay(500); + setTipPWM(0); // disable the output driver if the output is set to be off +#ifdef MODEL_TS100 + for (uint8_t i = 0; i < 50; i++) { + osDelay(10); + getTipRawTemp(1); // cycle up the tip temp filter + HAL_IWDG_Refresh(&hiwdg); + } +#else + // On the TS80 we can measure the tip resistance before cycling the filter a + // bit + idealQCVoltage = 0; + idealQCVoltage = calculateMaxVoltage(0, systemSettings.cutoutSetting); + // Rapidly cycle the filter to help converge + HAL_IWDG_Refresh(&hiwdg); + for (uint8_t i = 0; i < 50; i++) { + osDelay(11); + getTipRawTemp(1); // cycle up the tip temp filter + } + HAL_IWDG_Refresh(&hiwdg); + +#endif + currentlyActiveTemperatureTarget = 0; // Force start with no output (off). If in sleep / soldering this will + // be over-ridded rapidly int32_t integralCount = 0; int32_t derivativeLastValue = 0; -// REMEBER ^^^^ These constants are backwards -// They act as dividers, so to 'increase' a P term, you make the number -// smaller. + // REMEBER ^^^^ These constants are backwards + // They act as dividers, so to 'increase' a P term, you make the number + // smaller. const int32_t itermMax = 100; pidTaskNotification = xTaskGetCurrentTaskHandle(); for (;;) { - if (ulTaskNotifyTake( pdTRUE, 50)) { - //Wait a max of 50ms - //This is a call to block this thread until the ADC does its samples + if (ulTaskNotifyTake(pdTRUE, 50)) { + // Wait a max of 50ms + // This is a call to block this thread until the ADC does its samples uint16_t rawTemp = getTipRawTemp(1); // get instantaneous reading if (currentlyActiveTemperatureTarget) { // Compute the PID loop in here - // Because our values here are quite large for all measurements (0-32k ~= - // 66 counts per C) - // P I & D are divisors, so inverse logic applies (beware) + // Because our values here are quite large for all measurements (0-32k + // ~= 66 counts per C) P I & D are divisors, so inverse logic applies + // (beware) // Cap the max set point to 450C if (currentlyActiveTemperatureTarget > ctoTipMeasurement(450)) { @@ -910,8 +995,18 @@ void __attribute__ ((long_call, section (".data.ramfuncs"))) startPIDTask(void c } #define MOVFilter 8 void startMOVTask(void const *argument __unused) { +#ifdef MODEL_TS80 + startQC(); + while (idealQCVoltage == 0) + osDelay(20); // To ensure we return after idealQCVoltage is setup + + seekQC(idealQCVoltage); // this will move the QC output to the preferred voltage to start with + +#else osDelay(250); // wait for accelerometer to stabilize - lcd.setRotation(systemSettings.OrientationMode & 1); +#endif + + OLED::setRotation(systemSettings.OrientationMode & 1); lastMovementTime = 0; int16_t datax[MOVFilter] = { 0 }; int16_t datay[MOVFilter] = { 0 }; @@ -927,18 +1022,18 @@ void startMOVTask(void const *argument __unused) { Orientation rotation = ORIENTATION_FLAT; for (;;) { int32_t threshold = 1500 + (9 * 200); - threshold -= systemSettings.sensitivity * 200; // 200 is the step size + threshold -= systemSettings.sensitivity * 200; // 200 is the step size if (PCBVersion == 2) { - accel2.getAxisReadings(&tx, &ty, &tz); - rotation = accel2.getOrientation(); + LIS2DH12::getAxisReadings(&tx, &ty, &tz); + rotation = LIS2DH12::getOrientation(); } else if (PCBVersion == 1) { - accel.getAxisReadings(&tx, &ty, &tz); - rotation = accel.getOrientation(); + MMA8652FC::getAxisReadings(&tx, &ty, &tz); + rotation = MMA8652FC::getOrientation(); } if (systemSettings.OrientationMode == 2) { if (rotation != ORIENTATION_FLAT) { - lcd.setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through + OLED::setRotation(rotation == ORIENTATION_LEFT_HAND); // link the data through } } datax[currentPointer] = (int32_t) tx; @@ -956,26 +1051,26 @@ void startMOVTask(void const *argument __unused) { avgy /= MOVFilter; avgz /= MOVFilter; - //Sum the deltas + // Sum the deltas int32_t error = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)); #if ACCELDEBUG // Debug for Accel - lcd.setFont(1); - lcd.setCursor(0, 0); - lcd.printNumber(abs(avgx - (int32_t) tx), 5); - lcd.print(" "); - lcd.printNumber(abs(avgy - (int32_t) ty), 5); + OLED::setFont(1); + OLED::setCursor(0, 0); + OLED::printNumber(abs(avgx - (int32_t)tx), 5); + OLED::print(" "); + OLED::printNumber(abs(avgy - (int32_t)ty), 5); if (error > max) { max = (abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)); } - lcd.setCursor(0, 8); - lcd.printNumber(max, 5); - lcd.print(" "); + OLED::setCursor(0, 8); + OLED::printNumber(max, 5); + OLED::print(" "); - lcd.printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5); - lcd.refresh(); + OLED::printNumber((abs(avgx - tx) + abs(avgy - ty) + abs(avgz - tz)), 5); + OLED::refresh(); if (HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET) { max = 0; } @@ -990,6 +1085,11 @@ void startMOVTask(void const *argument __unused) { } osDelay(100); // Slow down update rate +#ifdef MODEL_TS80 + if (currentlyActiveTemperatureTarget) { + seekQC(idealQCVoltage); // Run the QC seek again to try and compensate for cable V drop + } +#endif } } @@ -997,9 +1097,9 @@ void startMOVTask(void const *argument __unused) { (0x8000000 | 0xF800) /*second last page of flash set aside for logo image*/ bool showBootLogoIfavailable() { -// check if the header is there (0xAA,0x55,0xF0,0x0D) -// If so display logo - //TODO REDUCE STACK ON THIS ONE, USE DRAWING IN THE READ LOOP + // check if the header is there (0xAA,0x55,0xF0,0x0D) + // If so display logo + // TODO REDUCE STACK ON THIS ONE, USE DRAWING IN THE READ LOOP uint16_t temp[98]; for (uint8_t i = 0; i < (98); i++) { @@ -1020,17 +1120,17 @@ bool showBootLogoIfavailable() { if (temp8[3] != 0x0D) return false; - lcd.drawArea(0, 0, 96, 16, (uint8_t *) (temp8 + 4)); - lcd.refresh(); + OLED::drawArea(0, 0, 96, 16, (uint8_t *) (temp8 + 4)); + OLED::refresh(); return true; } /* - * Catch the IRQ that says that the conversion is done on the temperature readings coming in - * Once these have come in we can unblock the PID so that it runs again + * Catch the IRQ that says that the conversion is done on the temperature + * readings coming in Once these have come in we can unblock the PID so that it + * runs again */ -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_ADCEx_InjectedConvCpltCallback( - ADC_HandleTypeDef* hadc) { +void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; if (hadc == &hadc1) { if (pidTaskNotification) { @@ -1040,34 +1140,26 @@ void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_ADCEx_InjectedC } } } - -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_MasterRxCpltCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_MasterTxCpltCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_MemTxCpltCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_ErrorCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_AbortCpltCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void __attribute__ ((long_call, section (".data.ramfuncs"))) HAL_I2C_MemRxCpltCallback( - I2C_HandleTypeDef *hi2c __unused) { - i2cDev.CpltCallback(); +void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { + FRToSI2C::CpltCallback(); } -void vApplicationStackOverflowHook( xTaskHandle *pxTask __unused, +void vApplicationStackOverflowHook(xTaskHandle *pxTask __unused, signed portCHAR *pcTaskName __unused) { -//We dont have a good way to handle a stack overflow at this point in time + // We dont have a good way to handle a stack overflow at this point in time NVIC_SystemReset(); - } diff --git a/workspace/TS100/src/stm32f1xx_hal_msp.c b/workspace/TS100/src/stm32f1xx_hal_msp.c index 0057ed84..f5243656 100644 --- a/workspace/TS100/src/stm32f1xx_hal_msp.c +++ b/workspace/TS100/src/stm32f1xx_hal_msp.c @@ -41,18 +41,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { if (hadc->Instance == ADC1) { __HAL_RCC_ADC1_CLK_ENABLE() ; - /**ADC1 GPIO Configuration - PA7 ------> ADC1_IN7 - PB0 ------> ADC1_IN8 - PB1 ------> ADC1_IN9 - */ - GPIO_InitStruct.Pin = TMP36_INPUT_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(TMP36_INPUT_GPIO_Port, &GPIO_InitStruct); - - GPIO_InitStruct.Pin = TIP_TEMP_Pin | VIN_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* ADC1 DMA Init */ /* ADC1 Init */ @@ -100,7 +88,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c) { GPIO_InitStruct.Pin = SCL_Pin | SDA_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral clock enable */ diff --git a/workspace/TS100/src/syscalls.c b/workspace/TS100/src/syscalls.c index 855079c9..2af03c8a 100644 --- a/workspace/TS100/src/syscalls.c +++ b/workspace/TS100/src/syscalls.c @@ -45,25 +45,12 @@ void _exit (int status) int _read (int file, char *ptr, int len) { - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - *ptr++ = __io_getchar(); - } - -return len; + return 0; } int _write(int file, char *ptr, int len) { - int DataIdx; - - for (DataIdx = 0; DataIdx < len; DataIdx++) - { - __io_putchar(*ptr++); - } - return len; + return 0; } caddr_t _sbrk(int incr) diff --git a/workspace/TS100A/.project b/workspace/TS100A/.project index bec4d1c2..6d126fab 100644 --- a/workspace/TS100A/.project +++ b/workspace/TS100A/.project @@ -165,11 +165,6 @@ 1 PARENT-1-PROJECT_LOC/TS100/inc/stm32f1xx_it.h - - inc/uRender.hpp - 1 - PARENT-1-PROJECT_LOC/TS100/inc/uRender.hpp - src/FRToSI2C.cpp 1 @@ -250,11 +245,6 @@ 1 PARENT-1-PROJECT_LOC/TS100/src/system_stm32f1xx.c - - src/uRender.cpp - 1 - PARENT-1-PROJECT_LOC/TS100/src/uRender.cpp - startup/startup_stm32.s 1 diff --git a/workspace/TS100A/.settings/language.settings.xml b/workspace/TS100A/.settings/language.settings.xml index b3648380..abe26fb1 100644 --- a/workspace/TS100A/.settings/language.settings.xml +++ b/workspace/TS100A/.settings/language.settings.xml @@ -4,7 +4,7 @@ - +