Skip to content

Commit

Permalink
feat(i2c): implement clock speed registers
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Nov 16, 2023
1 parent 3acc2e6 commit 75abb85
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/peripherals/i2c.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export class RPI2C extends BasePeripheral implements Peripheral {
rxThreshold = 0;
txThreshold = 0;
control = IC_SLAVE_DISABLE | IC_RESTART_EN | (I2CSpeed.FastMode << SPEED_SHIFT) | MASTER_MODE;
ssClockHighPeriod = 0x0028;
ssClockLowPeriod = 0x002f;
fsClockHighPeriod = 0x0006;
fsClockLowPeriod = 0x000d;
targetAddress = 0x55;
slaveAddress = 0x55;
abortSource = 0;
Expand All @@ -176,6 +180,14 @@ export class RPI2C extends BasePeripheral implements Peripheral {
return ((this.control >> SPEED_SHIFT) & SPEED_MASK) as I2CSpeed;
}

get sclLowPeriod() {
return this.speed === I2CSpeed.Standard ? this.ssClockLowPeriod : this.fsClockLowPeriod;
}

get sclHighPeriod() {
return this.speed === I2CSpeed.Standard ? this.ssClockHighPeriod : this.fsClockHighPeriod;
}

get masterBits() {
return this.control & IC_10BITADDR_MASTER ? 10 : 7;
}
Expand Down Expand Up @@ -349,6 +361,14 @@ export class RPI2C extends BasePeripheral implements Peripheral {
}
this.clearInterrupts(R_RX_FULL);
return this.rxFIFO.pull();
case IC_SS_SCL_HCNT:
return this.ssClockHighPeriod;
case IC_SS_SCL_LCNT:
return this.ssClockLowPeriod;
case IC_FS_SCL_HCNT:
return this.fsClockHighPeriod;
case IC_FS_SCL_LCNT:
return this.fsClockLowPeriod;
case IC_INTR_STAT:
return this.intStatus;
case IC_INTR_MASK:
Expand Down Expand Up @@ -453,6 +473,22 @@ export class RPI2C extends BasePeripheral implements Peripheral {
}
return;

case IC_SS_SCL_HCNT:
this.ssClockHighPeriod = value & 0xffff;
return;

case IC_SS_SCL_LCNT:
this.ssClockLowPeriod = value & 0xffff;
return;

case IC_FS_SCL_HCNT:
this.fsClockHighPeriod = value & 0xffff;
return;

case IC_FS_SCL_LCNT:
this.fsClockLowPeriod = value & 0xffff;
return;

case IC_RX_TL:
this.rxThreshold = value & 0xff;
if (this.rxThreshold > this.rxFIFO.size) {
Expand Down

0 comments on commit 75abb85

Please sign in to comment.