Skip to content

Commit 35d660b

Browse files
committed
Logic for spikelen register, enable_status register and sda_hold
1 parent 39fafbc commit 35d660b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/peripherals/i2c.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ export class RPI2C extends BasePeripheral implements Peripheral {
171171
abortSource = 0;
172172
intRaw = 0;
173173
intEnable = 0;
174+
private spikelen = 0x07;
174175

175176
get intStatus() {
176177
return this.intRaw & this.intEnable;
@@ -428,11 +429,18 @@ export class RPI2C extends BasePeripheral implements Peripheral {
428429
return this.txFIFO.itemCount;
429430
case IC_RXFLR:
430431
return this.rxFIFO.itemCount;
432+
case IC_SDA_HOLD:
433+
return 0x01;
431434
case IC_TX_ABRT_SOURCE: {
432435
const value = this.abortSource;
433436
this.abortSource &= ABRT_SBYTE_NORSTRT; // Clear IC_TX_ABRT_SOURCE, expect for bit 9
434437
return value;
435438
}
439+
case IC_ENABLE_STATUS:
440+
// I2C status - read only. bit 0 reflects IC_ENABLE, bit 1,2 relate to i2c slave mode.
441+
return this.enable & 0x1;
442+
case IC_FS_SPKLEN:
443+
return this.spikelen & 0xff
436444
case IC_COMP_PARAM_1:
437445
// From the datasheet:
438446
// Note This register is not implemented and therefore reads as 0. If it was implemented it would be a constant read-only
@@ -489,6 +497,14 @@ export class RPI2C extends BasePeripheral implements Peripheral {
489497
this.fsClockLowPeriod = value & 0xffff;
490498
return;
491499

500+
case IC_SDA_HOLD:
501+
if (!(value & ENABLE)) {
502+
if (value != 0x1) {
503+
this.warn('Unimplemented write to IC_SDA_HOLD')
504+
}
505+
}
506+
return;
507+
492508
case IC_RX_TL:
493509
this.rxThreshold = value & 0xff;
494510
if (this.rxThreshold > this.rxFIFO.size) {
@@ -522,6 +538,12 @@ export class RPI2C extends BasePeripheral implements Peripheral {
522538
this.nextCommand(); // TX_CMD_BLOCK may have changed
523539
return;
524540

541+
case IC_FS_SPKLEN:
542+
if (!(value & ENABLE) && value > 0) {
543+
this.spikelen = value;
544+
}
545+
return;
546+
525547
default:
526548
super.writeUint32(offset, value);
527549
}

0 commit comments

Comments
 (0)