betrusted-renode/kbd-soc.cs

109 lines
3.4 KiB
C#
Raw Normal View History

//
// Copyright (c) 2010 - 2019 Antmicro
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using System.Linq;
using Antmicro.Renode.Backends.Display;
using Antmicro.Renode.Core;
using Antmicro.Renode.Core.Structure.Registers;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Bus;
using Antmicro.Renode.Peripherals.Memory;
using Antmicro.Renode.Utilities;
namespace Antmicro.Renode.Peripherals.Input
{
public class betrusted_kbd : IKeyboard, IDoubleWordPeripheral, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IKnownSize
{
public betrusted_kbd(Machine machine) : base(machine)
{
this.machine = machine;
RegistersCollection = new DoubleWordRegisterCollection(this);
for (int i = 0; i < buffer.Length; i++) buffer[i] = 0;
// DefineRegisters();
Reset();
}
public void WriteDoubleWord(long address, uint value)
{
RegistersCollection.Write(address, value);
}
public uint ReadDoubleWord(long offset)
{
return RegistersCollection.Read(offset);
}
public override void Reset()
{
RegistersCollection.Reset();
}
public long Size { get{ return 0x800; }}
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
// protected override void Repaint()
// {
// var newbuf = new Byte[44*Height];
// machine.SystemBus.ReadBytes(bufferAddress, newbuf.Length, newbuf, 0);
// for (int y = 0; y < Height; y++) {
// if (!updateDirty || updateAll || ((newbuf[y*44+0x2a] & 0x1) == 0x1)) for (int x = 0; x < Width; x++) {
// if (((newbuf[((x+y*44*8))/8] >> (x%8))&1) > 0) {
// buffer[2*(x+y*Width)] = 0xFF;
// buffer[2*(x+y*Width)+1] = 0xFF;
// } else {
// buffer[2*(x+y*Width)] = 0x0;
// buffer[2*(x+y*Width)+1] = 0x0;
// }
// }
// }
// }
// private void DefineRegisters()
// {
// Registers.COMMAND.Define(this)
// .WithValueField(0, 32, writeCallback: (_, val) =>
// {
// updateDirty = (val & 0x1) == 0x1;
// updateAll = (val & 0x10) == 0x10;
// DoRepaint();
// })
// ;
// }
private readonly Machine machine;
private enum Registers
{
ROW0DAT1 = 0x0,
ROW0DAT0 = 0x4,
ROW1DAT1 = 0x8,
ROW1DAT0 = 0xc,
ROW2DAT1 = 0x10,
ROW2DAT0 = 0x14,
ROW3DAT1 = 0x18,
ROW3DAT0 = 0x1c,
ROW4DAT1 = 0x20,
ROW4DAT0 = 0x24,
ROW5DAT1 = 0x28,
ROW5DAT0 = 0x2c,
ROW6DAT1 = 0x30,
ROW6DAT0 = 0x34,
ROW7DAT1 = 0x38,
ROW7DAT0 = 0x3c,
ROW8DAT1 = 0x40,
ROW8DAT0 = 0x44,
EV_STATUS = 0x48,
EV_PENDING = 0x4c,
EV_ENABLE = 0x50,
ROWCHANGE1 = 0x54,
ROWCHANGE0 = 0x58,
BUSY = 0x04
}
}
}