Skip to content

Commit 75abb85

Browse files
committed
feat(i2c): implement clock speed registers
1 parent 3acc2e6 commit 75abb85

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/peripherals/i2c.ts

+36
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export class RPI2C extends BasePeripheral implements Peripheral {
162162
rxThreshold = 0;
163163
txThreshold = 0;
164164
control = IC_SLAVE_DISABLE | IC_RESTART_EN | (I2CSpeed.FastMode << SPEED_SHIFT) | MASTER_MODE;
165+
ssClockHighPeriod = 0x0028;
166+
ssClockLowPeriod = 0x002f;
167+
fsClockHighPeriod = 0x0006;
168+
fsClockLowPeriod = 0x000d;
165169
targetAddress = 0x55;
166170
slaveAddress = 0x55;
167171
abortSource = 0;
@@ -176,6 +180,14 @@ export class RPI2C extends BasePeripheral implements Peripheral {
176180
return ((this.control >> SPEED_SHIFT) & SPEED_MASK) as I2CSpeed;
177181
}
178182

183+
get sclLowPeriod() {
184+
return this.speed === I2CSpeed.Standard ? this.ssClockLowPeriod : this.fsClockLowPeriod;
185+
}
186+
187+
get sclHighPeriod() {
188+
return this.speed === I2CSpeed.Standard ? this.ssClockHighPeriod : this.fsClockHighPeriod;
189+
}
190+
179191
get masterBits() {
180192
return this.control & IC_10BITADDR_MASTER ? 10 : 7;
181193
}
@@ -349,6 +361,14 @@ export class RPI2C extends BasePeripheral implements Peripheral {
349361
}
350362
this.clearInterrupts(R_RX_FULL);
351363
return this.rxFIFO.pull();
364+
case IC_SS_SCL_HCNT:
365+
return this.ssClockHighPeriod;
366+
case IC_SS_SCL_LCNT:
367+
return this.ssClockLowPeriod;
368+
case IC_FS_SCL_HCNT:
369+
return this.fsClockHighPeriod;
370+
case IC_FS_SCL_LCNT:
371+
return this.fsClockLowPeriod;
352372
case IC_INTR_STAT:
353373
return this.intStatus;
354374
case IC_INTR_MASK:
@@ -453,6 +473,22 @@ export class RPI2C extends BasePeripheral implements Peripheral {
453473
}
454474
return;
455475

476+
case IC_SS_SCL_HCNT:
477+
this.ssClockHighPeriod = value & 0xffff;
478+
return;
479+
480+
case IC_SS_SCL_LCNT:
481+
this.ssClockLowPeriod = value & 0xffff;
482+
return;
483+
484+
case IC_FS_SCL_HCNT:
485+
this.fsClockHighPeriod = value & 0xffff;
486+
return;
487+
488+
case IC_FS_SCL_LCNT:
489+
this.fsClockLowPeriod = value & 0xffff;
490+
return;
491+
456492
case IC_RX_TL:
457493
this.rxThreshold = value & 0xff;
458494
if (this.rxThreshold > this.rxFIFO.size) {

0 commit comments

Comments
 (0)