diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-11-20 13:47:17 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-11-20 13:52:16 -0500 |
commit | bb08dc7ae91488a6e9e1e88de28bd43be9fa5651 (patch) | |
tree | 0f8255ecf3f5d4bd4a9b66db302795071533ba64 /src/atsam/i2c.c | |
parent | 92ca1119868abbd859c8f7a3f88143cf53561eb3 (diff) | |
download | kutter-bb08dc7ae91488a6e9e1e88de28bd43be9fa5651.tar.gz kutter-bb08dc7ae91488a6e9e1e88de28bd43be9fa5651.tar.xz kutter-bb08dc7ae91488a6e9e1e88de28bd43be9fa5651.zip |
atsam: Add get_pclock_frequency() helper function
Add get_pclock_frequency() and use it to calculate peripheral clocks.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/atsam/i2c.c')
-rw-r--r-- | src/atsam/i2c.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/atsam/i2c.c b/src/atsam/i2c.c index fc56ce50..f7e68b81 100644 --- a/src/atsam/i2c.c +++ b/src/atsam/i2c.c @@ -48,8 +48,9 @@ i2c_init(Twi *p_twi, uint32_t rate) p_twi->TWI_CR = TWI_CR_SVDIS; p_twi->TWI_CR = TWI_CR_MSEN; + uint32_t pclk = get_pclock_frequency(p_twi == TWI0 ? ID_TWI0 : ID_TWI1); uint32_t cldiv = 0, chdiv = 0, ckdiv = 0; - cldiv = SystemCoreClock / ((rate > 384000 ? 384000 : rate) * 2) - 4; + cldiv = pclk / ((rate > 384000 ? 384000 : rate) * 2) - 4; while ((cldiv > 255) && (ckdiv < 7)) { ckdiv++; @@ -57,7 +58,7 @@ i2c_init(Twi *p_twi, uint32_t rate) } if (rate > 348000) { - chdiv = SystemCoreClock / ((2 * rate - 384000) * 2) - 4; + chdiv = pclk / ((2 * rate - 384000) * 2) - 4; while ((chdiv > 255) && (ckdiv < 7)) { ckdiv++; chdiv /= 2; |