|
29 | 29 | #include "bme280.h" |
30 | 30 | #include "bh1750.h" |
31 | 31 | #include "utils/i2cutils.h" |
| 32 | +#include "utils/uartutils.h" |
32 | 33 |
|
33 | 34 | // =================== Hard constants ================= |
34 | 35 | // #1: Timings |
@@ -102,7 +103,6 @@ typedef struct { |
102 | 103 | } PeriodicCallbackDesc; |
103 | 104 |
|
104 | 105 | // ================ Local function declarations ================= |
105 | | -static void _uart_println(const char *pcPrefix, const char *pcLine, uint8_t u8Len); |
106 | 106 | static void _flush_message(uint64_t u64tckTimestamp); |
107 | 107 | static void _alternate_value(void *pvParam); |
108 | 108 | static ELockmgrResource _i2c_to_lock(EI2CBus eBus); |
@@ -171,20 +171,6 @@ static PeriodicCallbackDesc gsPCbDesc = { |
171 | 171 | }; |
172 | 172 |
|
173 | 173 |
|
174 | | -// Implementation |
175 | | - |
176 | | -static void _uart_println(const char *pcPrefix, const char *pcLine, uint8_t u8Len) { |
177 | | - uint32_t u32PfxLen = strlen(pcPrefix); |
178 | | - for (int i = 0; i < u32PfxLen; ++i) { |
179 | | - gpsUART0->FIFO = pcPrefix[i]; |
180 | | - } |
181 | | - for (int i = 0; i < u8Len; ++i) { |
182 | | - gpsUART0->FIFO = pcLine[i]; |
183 | | - } |
184 | | - gpsUART0->FIFO = '\r'; |
185 | | - gpsUART0->FIFO = '\n'; |
186 | | -} |
187 | | - |
188 | 174 | static void _flush_message(uint64_t u64tckTimestamp) { |
189 | 175 | static uint8_t u8Phase; |
190 | 176 | static char buf[LOG_BUFLEN]; |
@@ -228,7 +214,7 @@ static void _flush_message(uint64_t u64tckTimestamp) { |
228 | 214 | // some internal call causes WDT |
229 | 215 | snprintf(buf, LOG_BUFLEN, "%s%"PRIu64"%s", message_pfx, u64tckTimestamp, message_sfx); |
230 | 216 | } |
231 | | - _uart_println("LOG:\tts ", buf, buf_e - buf); |
| 217 | + uart_printf(gpsUART0, "LOG:\tts %.*s\r\n", buf_e - buf, buf); |
232 | 218 | ++u8Phase; |
233 | 219 | } |
234 | 220 |
|
@@ -398,20 +384,10 @@ static void _bme280_init(SBme280StateDesc *psState, SI2cIfaceCfg *psIface) { |
398 | 384 | } |
399 | 385 |
|
400 | 386 | static void _bme280_print_result(const SBme280TPH *psRes, uint32_t u32TFine) { |
401 | | - char acBuf[20]; |
402 | | - char *bufE; |
403 | | - bufE = print_dec(acBuf, u32TFine); |
404 | | - _uart_println("Tfine: ", acBuf, bufE - acBuf); |
405 | | - bufE = print_deccent(acBuf, psRes->i32Temp, '.'); |
406 | | - _uart_println("Temp: ", acBuf, bufE - acBuf); |
407 | | - bufE = print_dec(acBuf, psRes->i32Pres >> 8); |
408 | | - *(bufE++) = '.'; |
409 | | - bufE = print_dec_padded(bufE, ((psRes->i32Pres & 0xff)*391) / 1000, 2, '0'); |
410 | | - _uart_println("Pres: ", acBuf, bufE - acBuf); |
411 | | - bufE = print_dec(acBuf, psRes->i32Hum >> 10); |
412 | | - *(bufE++) = '.'; |
413 | | - bufE = print_dec_padded(bufE, ((psRes->i32Hum & 0x3ff)*97657) / 100000, 3, '0'); |
414 | | - _uart_println("Hum: ", acBuf, bufE - acBuf); |
| 387 | + uart_printf(gpsUART0, "Tfine: %d\r\n", u32TFine); |
| 388 | + uart_printf(gpsUART0, "Temp: %d.%02d\r\n", psRes->i32Temp / 100, psRes->i32Temp % 100); |
| 389 | + uart_printf(gpsUART0, "Pres: %d.%02d\r\n", psRes->i32Pres >> 8, ((psRes->i32Pres & 0xff)*391) / 1000); |
| 390 | + uart_printf(gpsUART0, "Hum: %d.%03d\r\n", psRes->i32Hum >> 10, ((psRes->i32Hum & 0x3ff)*97657) / 100000); |
415 | 391 | } |
416 | 392 |
|
417 | 393 | static void _bme280_cycle(uint64_t u64Ticks) { |
@@ -464,13 +440,8 @@ static void _bh1750_print_result(const SBh1750StateDesc *psState) { |
464 | 440 | uint8_t u8MTime = bh1750_get_mtime(psState); |
465 | 441 | uint8_t u16Result = conv16be(psState->u16beResult); |
466 | 442 | uint32_t u32mLx = bh1750_result_to_mlx(u16Result, u8MTime, eMRes); |
467 | | - char acBuf[40]; |
468 | | - char *pcBufE = acBuf; |
469 | | - pcBufE = str_append(pcBufE, acBh1750MResName[eMRes]); |
470 | | - pcBufE = str_append(pcBufE, ": "); |
471 | | - pcBufE = print_decmilli(pcBufE, u32mLx, '.'); |
472 | 443 |
|
473 | | - _uart_println("BH1750 ", acBuf, pcBufE - acBuf); |
| 444 | + uart_printf(gpsUART0, "BH1750 %s: %d.%03d\r\n", acBh1750MResName[eMRes], u32mLx/1000, u32mLx%1000); |
474 | 445 | } |
475 | 446 |
|
476 | 447 | static void _bh1750_cycle(uint64_t u64Ticks) { |
@@ -507,7 +478,7 @@ static void _bh1750_cycle(uint64_t u64Ticks) { |
507 | 478 | u8Retries = BH1750_READ_RETRIES; |
508 | 479 | } else { |
509 | 480 | // EITHER 0 was measured OR result still not ready |
510 | | - _uart_println("BH1750 retry", NULL, 0); |
| 481 | + uart_printf(gpsUART0, "BH1750 retry\r\n"); |
511 | 482 | u32hmsWaitHint += BH1750_RETRY_WAIT_HMS; // so let's wait some dt |
512 | 483 | } |
513 | 484 | break; |
@@ -602,13 +573,13 @@ static void _i2cscan_cycle(uint64_t u64Ticks) { |
602 | 573 | pcBufE = str_append(pcBufE, " 0x"); |
603 | 574 | pcBufE = print_hex8(pcBufE, i); |
604 | 575 | if (5 * I2CSCAN_PRINT_PER_ROW <= (pcBufE - acBuf)) { |
605 | | - _uart_println(acPfx, acBuf, pcBufE - acBuf); |
| 576 | + uart_printf(gpsUART0, "%s%.*s\r\n", acPfx, pcBufE - acBuf, acBuf); |
606 | 577 | pcBufE = acBuf; |
607 | 578 | } |
608 | 579 | } |
609 | 580 | } |
610 | 581 | if (pcBufE != acBuf) { |
611 | | - _uart_println(acPfx, acBuf, pcBufE - acBuf); |
| 582 | + uart_printf(gpsUART0, "%s%.*s\r\n", acPfx, pcBufE - acBuf, acBuf); |
612 | 583 | } |
613 | 584 |
|
614 | 585 | u64NextTick += MS2TICKS(I2CSCAN_PERIOD_MS); |
|
0 commit comments