mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
emulation: add initial files for lcd and keyboard
keyboard doesn't work yet, possibly due to upstream bug. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
672896a1a3
commit
c8ccbe27c1
2 changed files with 200 additions and 0 deletions
103
emulation/peripherals/keyboard.cs
Normal file
103
emulation/peripherals/keyboard.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
//
|
||||
// Copyright (c) 2010-2018 Antmicro
|
||||
// Copyright (c) 2011-2015 Realtime Embedded
|
||||
//
|
||||
// This file is licensed under the MIT License.
|
||||
// Full license text is available in 'licenses/MIT.txt'.
|
||||
//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 BetrustedKbd : IKeyboard, IDoubleWordPeripheral, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IKnownSize
|
||||
{
|
||||
public BetrustedKbd(Machine machine)
|
||||
{
|
||||
this.machine = machine;
|
||||
RegistersCollection = new DoubleWordRegisterCollection(this);
|
||||
data = new Queue<byte>();
|
||||
Reset();
|
||||
data.Enqueue((byte)Command.SelfTestPassed);
|
||||
}
|
||||
|
||||
|
||||
public void WriteDoubleWord(long address, uint value)
|
||||
{
|
||||
RegistersCollection.Write(address, value);
|
||||
}
|
||||
|
||||
public uint ReadDoubleWord(long offset)
|
||||
{
|
||||
return RegistersCollection.Read(offset);
|
||||
}
|
||||
|
||||
public long Size { get { return 4096; }}
|
||||
public DoubleWordRegisterCollection RegistersCollection { get; private set; }
|
||||
|
||||
public void Press(KeyScanCode scanCode)
|
||||
{
|
||||
this.Log(LogLevel.Error, "Pressed key {0}", scanCode);
|
||||
var key = PS2ScanCodeTranslator.Instance.GetCode(scanCode);
|
||||
data.Enqueue((byte)(key & 0x7f));
|
||||
NotifyParent();
|
||||
}
|
||||
|
||||
public void Release(KeyScanCode scanCode)
|
||||
{
|
||||
this.Log(LogLevel.Noisy, "Released key {0}", scanCode);
|
||||
var key = PS2ScanCodeTranslator.Instance.GetCode(scanCode);
|
||||
data.Enqueue((byte)Command.Release);
|
||||
data.Enqueue((byte)(key & 0x7f));
|
||||
NotifyParent();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
data.Clear();
|
||||
}
|
||||
|
||||
public IPS2Controller Controller { get; set; }
|
||||
|
||||
private void SendAck()
|
||||
{
|
||||
data.Enqueue((byte)Command.Acknowledge);
|
||||
NotifyParent();
|
||||
}
|
||||
|
||||
private void NotifyParent()
|
||||
{
|
||||
if(Controller != null)
|
||||
{
|
||||
if(data.Count > 0)
|
||||
{
|
||||
Controller.Notify();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Log(LogLevel.Noisy, "PS2 device not connected to any controller issued an update.");
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Queue<byte> data;
|
||||
private readonly Machine machine;
|
||||
private const ushort deviceId = 0xABBA;
|
||||
|
||||
private enum Command
|
||||
{
|
||||
Reset = 0xFF,
|
||||
Acknowledge = 0xFA,
|
||||
ReadId = 0xF2,
|
||||
SetResetLeds = 0xED,
|
||||
Release = 0xF0,
|
||||
SelfTestPassed = 0xAA,
|
||||
}
|
||||
}
|
||||
}
|
||||
97
emulation/peripherals/memlcd.cs
Normal file
97
emulation/peripherals/memlcd.cs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// 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.Video
|
||||
{
|
||||
public class BetrustedLCD : AutoRepaintingVideo, IDoubleWordPeripheral, IProvidesRegisterCollection<DoubleWordRegisterCollection>, IKnownSize
|
||||
{
|
||||
public BetrustedLCD(Machine machine) : base(machine)
|
||||
{
|
||||
this.machine = machine;
|
||||
|
||||
RegistersCollection = new DoubleWordRegisterCollection(this);
|
||||
Reconfigure(336, 536, PixelFormat.RGB565, true);
|
||||
for (int i = 0; i < buffer.Length; i++) buffer[i] = 0;
|
||||
DoRepaint();
|
||||
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 & 0x2) == 0x2;
|
||||
DoRepaint();
|
||||
})
|
||||
;
|
||||
Registers.BUSY.Define(this)
|
||||
.WithValueField(0, 32, valueProviderCallback: _ => { return 0; })
|
||||
;
|
||||
}
|
||||
|
||||
private bool updateDirty = false;
|
||||
private bool updateAll = false;
|
||||
|
||||
private uint bufferAddress = 0xB0000000;
|
||||
|
||||
private readonly Machine machine;
|
||||
|
||||
private enum Registers
|
||||
{
|
||||
COMMAND = 0x0,
|
||||
BUSY = 0x04
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue