From ee35ffd297ead91ca7c641a920ca4b816901e314 Mon Sep 17 00:00:00 2001 From: tianjialong Date: Mon, 1 May 2023 14:29:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=A9=E5=BA=A6=E4=BC=A0?= =?UTF-8?q?=E6=84=9F=E5=99=A8=E6=B8=A9=E5=BA=A6=E5=91=A8=E6=9C=9F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/MDK-ARM/app.uvguix.29643 | 2 +- src/board/hardware.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++- src/board/hardware.hpp | 28 ++++++++++++++++++++++++- src/board/project_board.hpp | 5 ++++- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/app/MDK-ARM/app.uvguix.29643 b/app/MDK-ARM/app.uvguix.29643 index 0a910d1..d5d497e 100644 --- a/app/MDK-ARM/app.uvguix.29643 +++ b/app/MDK-ARM/app.uvguix.29643 @@ -1822,7 +1822,7 @@ Build 966 - 00200000010000001000FFFF01001100434D4643546F6F6C426172427574746F6ECF7F0000000004001C0000000000000000000000000000000001000000010000000180D07F0000000000001D000000000000000000000000000000000100000001000000018030800000000002001E000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6EC7040000000000006A0000000C4261746368204275696C2664000000000000000000000000010000000100000000000000000000000100000004000580C7040000000000006A0000000C4261746368204275696C266400000000000000000000000001000000010000000000000000000000010000000000058046070000000000006B0000000D42617463682052656275696C640000000000000000000000000100000001000000000000000000000001000000000005804707000000000000FFFFFFFF0B426174636820436C65616E0100000000000000010000000000000001000000000000000000000001000000000005809E8A0000000000001F0000000F4261746326682053657475702E2E2E000000000000000000000000010000000100000000000000000000000100000000000180D17F0000000004002000000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001804C8A0000000000002100000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001900434D4643546F6F6C426172436F6D626F426F78427574746F6EBA0000000000000000000000000000000000000000000000000100000001000000960000000300205000000000036170709600000000000000010003617070000000000180EB880000000000002200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C07F000000000000230000000000000000000000000000000001000000010000000180B08A000000000400240000000000000000000000000000000001000000010000000180A8010000000000004E00000000000000000000000000000000010000000100000001807202000000000000530000000000000000000000000000000001000000010000000180BE010000000000005000000000000000000000000000000000010000000100000000000000054275696C64DC010000 + 00200000010000001000FFFF01001100434D4643546F6F6C426172427574746F6ECF7F0000000004001C0000000000000000000000000000000001000000010000000180D07F0000000002001D000000000000000000000000000000000100000001000000018030800000000000001E000000000000000000000000000000000100000001000000FFFF01001500434D4643546F6F6C4261724D656E75427574746F6EC7040000000000006A0000000C4261746368204275696C2664000000000000000000000000010000000100000000000000000000000100000004000580C7040000000000006A0000000C4261746368204275696C266400000000000000000000000001000000010000000000000000000000010000000000058046070000000000006B0000000D42617463682052656275696C640000000000000000000000000100000001000000000000000000000001000000000005804707000000000000FFFFFFFF0B426174636820436C65616E0100000000000000010000000000000001000000000000000000000001000000000005809E8A0000000000001F0000000F4261746326682053657475702E2E2E000000000000000000000000010000000100000000000000000000000100000000000180D17F0000000004002000000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF00000000000000000000000000010000000100000001804C8A0000000000002100000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF000000000000000000000000000100000001000000FFFF01001900434D4643546F6F6C426172436F6D626F426F78427574746F6EBA0000000000000000000000000000000000000000000000000100000001000000960000000300205000000000036170709600000000000000010003617070000000000180EB880000000000002200000000000000000000000000000000010000000100000001800000000001000000FFFFFFFF0000000000000000000000000001000000010000000180C07F000000000000230000000000000000000000000000000001000000010000000180B08A000000000400240000000000000000000000000000000001000000010000000180A8010000000000004E00000000000000000000000000000000010000000100000001807202000000000000530000000000000000000000000000000001000000010000000180BE010000000000005000000000000000000000000000000000010000000100000000000000054275696C64DC010000 583 diff --git a/src/board/hardware.cpp b/src/board/hardware.cpp index ff0176d..06dfdfd 100644 --- a/src/board/hardware.cpp +++ b/src/board/hardware.cpp @@ -14,10 +14,12 @@ int fputc(int ch, FILE *stream) { void Hardware::hardwareinit() { debug_light_init(); can_init(); + temperature_init(); } void Hardware::periodicJob() { debug_light_periodicJob(); can_periodicJob(); + temperature_periodicJob(); } /******************************************************************************* @@ -102,4 +104,49 @@ void Hardware::can_periodicJob() { can_send(m_can.tdata, 8); // 查询接收can消息,并通过UART1 打印接收到的CAN消息报文 can_receive(m_can.adata, 8); -} \ No newline at end of file +} + +/******************************************************************************* + * 温度 * + *******************************************************************************/ +void Hardware::temperature_init() { + m_temperature.tmp117[0].initializate(&hi2c1, TMP117::ID0); + m_temperature.tmp117[1].initializate(&hi2c1, TMP117::ID1); + m_temperature.tmp117[2].initializate(&hi2c1, TMP117::ID2); + m_temperature.tmp117[3].initializate(&hi2c1, TMP117::ID3); +} + +TMP117 *Hardware::temperature_get_tmp117(int off) { + if (off < 0 || off > 3) { + ZASSERT(0); + return NULL; + } + return &m_temperature.tmp117[off]; +} +float Hardware::temperature_get_temp(int off) { + if (off < 0 || off > 3) { + ZASSERT(0); + return 0; + } + return m_temperature.tmp117[off].getTemperature(); +} + +void Hardware::temperature_periodicJob() { + if (testHardwareFlag) { + /** + * @brief 周期打印温度 + */ + static uint32_t lastcall; + if (hasPassedMS(lastcall) > 1000) { + lastcall = getTicket(); + for (size_t i = 0; i < 4; i++) { + float temp = m_temperature.tmp117[i].getTemperature(); + if (m_temperature.tmp117[i].getLastCallStatus() == HAL_OK) { + ZLOGI(TAG, "tmp117_%d:%f", i, temp); + } else { + ZLOGI(TAG, "tmp117_%d:read fail", i); + } + } + } + } +} diff --git a/src/board/hardware.hpp b/src/board/hardware.hpp index c7e7fd8..363b32c 100644 --- a/src/board/hardware.hpp +++ b/src/board/hardware.hpp @@ -1,8 +1,12 @@ #pragma once #include "board/project_board.hpp" +#include "i2c.h" #include "libiflytop_micro/stm32/basic/basic.h" +#include "libiflytop_micro\stm32\basic\iflytop_micro_os.hpp" #include "libiflytop_micro\stm32\basic\stm32_hal.hpp" +#include "libiflytop_micro\stm32\component\tmp117\tmp117.hpp" +#include "tim.h" #include "usart.h" namespace iflytop { @@ -26,7 +30,12 @@ class Hardware { uint8_t adata[8]; uint32_t pTxMailbox; }; - can_res_t m_can; + struct temperature_res_t { + TMP117 tmp117[4]; + }; + can_res_t m_can; + temperature_res_t m_temperature; + bool testHardwareFlag; public: Hardware(/* args */){}; @@ -48,6 +57,23 @@ class Hardware { void can_HeaderTypedef_set(); void can_send(uint8_t *data, uint8_t len); void can_receive(uint8_t *data, uint8_t len); + + /******************************************************************************* + * 温度 * + *******************************************************************************/ + void temperature_init(); + TMP117 *temperature_get_tmp117(int off); + float temperature_get_temp(int off); + void temperature_periodicJob(); + + /******************************************************************************* + * OVERRIDE IflytopMicroOS * + *******************************************************************************/ + virtual void sleepMS(int ms) { HAL_Delay(ms); }; + virtual uint32_t hasPassedMS(uint32_t ticket) { return sys_haspassedms(ticket); }; + virtual uint32_t getTicket() { return HAL_GetTick(); }; + virtual uint32_t getNowMS() { return HAL_GetTick(); }; + virtual void sleepus(uint32_t us) { sys_delay_us(&DELAY_US_TIMER, us); } }; } // namespace iflytop diff --git a/src/board/project_board.hpp b/src/board/project_board.hpp index a8b02c6..50231dd 100644 --- a/src/board/project_board.hpp +++ b/src/board/project_board.hpp @@ -5,4 +5,7 @@ #define DEBUG_UART huart1 // 调试指示灯 #define DEBUG_LIGHT_PORT GPIOE -#define DEBUG_LIGHT_PIN GPIO_PIN_8 \ No newline at end of file +#define DEBUG_LIGHT_PIN GPIO_PIN_8 +// 微秒延迟定时器,注意该延时定时器需要按照以下文档进行配置 +// http://192.168.1.3:3000/zwikipedia/iflytop_wikipedia/src/branch/master/doc/stm32cubemx_us_timer.md +#define DELAY_US_TIMER htim6