Skip to content

Commit d906669

Browse files
committed
Replace hal timing with timing:: API
Replace legacy hal timing calls with the unified timing API across device and display code (hal_micros/hal_millis/udelay -> timing::Micros/ timing::Millis/ timing::DelayUs) and add timing.h includes where needed. Replace sentinel returns of static_cast<uint32_t>(~0) with UINT32_MAX. Refactor/clean up SPI/display headers and Paint implementation (formatting, brace/style changes, DrawLine integer handling), update copyright years in ST headers, and adjust dmxnode enum usage (PortDirection -> Direction). These changes unify timing, improve readability, and fix some portability/sentinel issues. Affected files include many under lib-device, lib-display, lib-displayudf, lib-osc, and lib-showfile.
1 parent afb027e commit d906669

15 files changed

Lines changed: 239 additions & 263 deletions

File tree

lib-device/include/bwspilcd.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include <cstdint>
3030

31-
#include "hal_micros.h"
31+
#include "timing.h"
3232

3333
#include "bw.h"
3434

@@ -38,11 +38,11 @@ class BwSpiLcd : BwSpi
3838
{
3939
do
4040
{
41-
} while ((hal::Micros() - m_nSpiWriteUs) < bw::lcd::spi::write_delay_us);
41+
} while ((timing::Micros() - m_nSpiWriteUs) < bw::lcd::spi::write_delay_us);
4242

4343
HAL_SPI::Write(pData, length);
4444

45-
m_nSpiWriteUs = hal::Micros();
45+
m_nSpiWriteUs = timing::Micros();
4646
}
4747

4848
public:
@@ -112,7 +112,7 @@ class BwSpiLcd : BwSpi
112112
bool IsConnected() { return m_IsConnected; }
113113

114114
private:
115-
uint32_t m_nSpiWriteUs = hal::Micros();
115+
uint32_t m_nSpiWriteUs = timing::Micros();
116116
};
117117

118118
#endif // BWSPILCD_H_

lib-device/include/sc16is740.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <cstdint>
3030

3131
#include "hal_i2c.h"
32-
#include "hal_millis.h"
32+
#include "timing.h"
3333

3434
#include "sc16is7x0.h"
3535

@@ -136,14 +136,14 @@ class SC16IS740 : HAL_I2C
136136

137137
bool IsReadable(uint32_t time_out)
138138
{
139-
const auto kMillis = hal::Millis();
139+
const auto kMillis = timing::Millis();
140140
do
141141
{
142142
if (IsReadable())
143143
{
144144
return true;
145145
}
146-
} while ((hal::Millis() - time_out) < kMillis);
146+
} while ((timing::Millis() - time_out) < kMillis);
147147

148148
return false;
149149
}

lib-device/src/htu21d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ uint16_t HTU21D::ReadRaw(uint8_t cmd)
7171

7272
for (uint32_t i = 0; i < 8; ++i)
7373
{
74-
udelay(10000);
74+
timing::DelayUs(10000);
7575
HAL_I2C::Read(buf, 3);
7676

7777
if ((buf[0] & 0x3) == 2)

lib-device/src/mcp3424.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ uint32_t MCP3424::GetRaw(uint32_t channel)
164164

165165
if (timeout-- == 0)
166166
{
167-
return static_cast<uint32_t>(~0);
167+
return UINT32_MAX;
168168
}
169169
}
170170

@@ -190,7 +190,7 @@ uint32_t MCP3424::GetRaw(uint32_t channel)
190190

191191
assert(0);
192192
__builtin_unreachable();
193-
return static_cast<uint32_t>(~0);
193+
return UINT32_MAX;
194194
}
195195

196196
double MCP3424::GetVoltage(uint32_t channel)

lib-device/src/sc16is740.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "sc16is740.h"
2929
#include "sc16is7x0.h"
3030

31-
#include "hal_millis.h"
31+
#include "timing.h"
3232
#include "hal_i2c.h"
3333
#include "firmware/debug/debug_printbits.h"
3434
#include "firmware/debug/debug_debug.h"
@@ -190,11 +190,11 @@ void SC16IS740::ReadBytes(uint8_t *bytes, uint32_t& size, uint32_t time_out) {
190190
uint32_t remaining = size;
191191

192192
while (remaining > 0) {
193-
const uint32_t kMillis =hal::Millis();
193+
const uint32_t kMillis =timing::Millis();
194194
uint32_t available;
195195

196196
while ((available = ReadRegister(SC16IS7X0_RXLVL)) == 0) {
197-
if ((hal::Millis() - time_out) > kMillis) {
197+
if ((timing::Millis() - time_out) > kMillis) {
198198
remaining = 0;
199199
break;
200200
}
@@ -218,11 +218,11 @@ void SC16IS740::FlushRead(uint32_t time_out) {
218218
bool is_remaining = true;
219219

220220
while (is_remaining) {
221-
const auto kMillis = hal::Millis();
221+
const auto kMillis = timing::Millis();
222222
uint32_t available;
223223

224224
while ((available = ReadRegister(SC16IS7X0_RXLVL)) == 0) {
225-
if ((hal::Millis() - time_out) > kMillis) {
225+
if ((timing::Millis() - time_out) > kMillis) {
226226
is_remaining = false;
227227
break;
228228
}

lib-device/src/si7021.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ uint16_t SI7021::ReadRaw(uint8_t cmd)
7171

7272
for (uint32_t i = 0; i < 8; ++i)
7373
{
74-
udelay(10000);
74+
timing::DelayUs(10000);
7575
HAL_I2C::Read(buf, 3);
7676

7777
if ((buf[0] & 0x3) == 2)

0 commit comments

Comments
 (0)