summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-10-16 10:03:10 +0700
committerhathach <[email protected]>2025-10-16 10:03:10 +0700
commite93e47ae0434b53a20d1c62de62f34377bc8b492 (patch)
tree935cfce49a05cd5b68808992535c9b0b20bb5d9c /src/class
parent79445c2386adefb207a76a70d87578b53c3e7922 (diff)
add tu_div_round_nearest() (only handle positive) to replace DIV_ROUND_CLOSEST() to remove the need of typeof
Diffstat (limited to 'src/class')
-rw-r--r--src/class/cdc/cdc_host.c4
-rw-r--r--src/class/cdc/serial/ftdi_sio.h13
2 files changed, 2 insertions, 15 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index beef03eff..b59b0d641 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -1365,7 +1365,7 @@ static uint32_t ftdi_232bm_baud_base_to_divisor(uint32_t baud, uint32_t base) {
uint8_t divfrac[8] = {0, 3, 2, 4, 1, 5, 6, 7};
uint32_t divisor;
/* divisor shifted 3 bits to the left */
- uint32_t divisor3 = DIV_ROUND_CLOSEST(base, 2 * baud);
+ uint32_t divisor3 = tu_div_round_nearest(base, 2 * baud);
divisor = divisor3 >> 3;
divisor |= (uint32_t) divfrac[divisor3 & 0x7] << 14;
/* Deal with special cases for highest baud rates. */
@@ -1387,7 +1387,7 @@ static uint32_t ftdi_2232h_baud_base_to_divisor(uint32_t baud, uint32_t base) {
uint32_t divisor3;
/* hi-speed baud rate is 10-bit sampling instead of 16-bit */
- divisor3 = DIV_ROUND_CLOSEST(8 * base, 10 * baud);
+ divisor3 = tu_div_round_nearest(8 * base, 10 * baud);
divisor = divisor3 >> 3;
divisor |= (uint32_t) divfrac[divisor3 & 0x7] << 14;
diff --git a/src/class/cdc/serial/ftdi_sio.h b/src/class/cdc/serial/ftdi_sio.h
index 8abf74f11..9bd56cef4 100644
--- a/src/class/cdc/serial/ftdi_sio.h
+++ b/src/class/cdc/serial/ftdi_sio.h
@@ -215,17 +215,4 @@ typedef struct ftdi_private {
#define FTDI_NOT_POSSIBLE -1
#define FTDI_REQUESTED -2
-// division and round function overtaken from math.h
-#define DIV_ROUND_CLOSEST(x, divisor)( \
-{ \
- typeof(x) __x = x; \
- typeof(divisor) __d = divisor; \
- (((typeof(x))-1) > 0 || \
- ((typeof(divisor))-1) > 0 || \
- (((__x) > 0) == ((__d) > 0))) ? \
- (((__x) + ((__d) / 2)) / (__d)) : \
- (((__x) - ((__d) / 2)) / (__d)); \
-} \
-)
-
#endif //TUSB_FTDI_SIO_H