blob: 959e7621f7cddf393fd97b2fd00cd605a49d55e2 [file]
//
// Copyright (c) 2022 Google LLC
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using System.IO;
using Antmicro.Renode.Exceptions;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Sensor;
using Antmicro.Renode.Peripherals.I2C;
namespace Antmicro.Renode.Peripherals.Sensors
{
public class Hm01b0Video : I2CPeripheralBase<HiMaxHM01B0.Registers>, ICPIPeripheral, ISensor
{
public Hm01b0Video() : base(16)
{
imageData = new byte[0];
imageIdx = 0;
LoadFrame();
}
public void Reset()
{
base.Reset();
imageIdx = 0;
LoadFrame();
}
void LoadFrame()
{
var filename = frames[imageIdx];
try
{
imageData = File.ReadAllBytes(filename);
this.NoisyLog("Loaded {0} bytes of image data to buffer", imageData.Length);
}
catch(Exception e)
{
throw new RecoverableException($"Could not load image {filename}: {(e.Message)}");
}
}
public byte[] ReadFrame()
{
var ret = imageData;
imageIdx += 1;
if(imageIdx == frames.Length) {
imageIdx = 0;
}
LoadFrame();
return ret;
}
protected override void DefineRegisters()
{
}
private byte[] imageData;
private uint imageIdx;
private string[] frames = {
"../../out/springbok_iree/quant_models/hps_0_quant_input",
"../../out/springbok_iree/quant_models/hps_1_quant_input",
"../../out/springbok_iree/quant_models/hps_2_quant_input",
"../../out/springbok_iree/quant_models/hps_3_quant_input",
"../../out/springbok_iree/quant_models/hps_4_quant_input",
"../../out/springbok_iree/quant_models/hps_5_quant_input",
};
// based on https://github.com/sparkfun/SparkFun_Apollo3_AmbiqSuite_BSPs/blob/master/common/third_party/hm01b0/HM01B0.h
public enum Registers
{
ModelIdHigh = 0x0000,
ModelIdLow = 0x0001,
SiliconRevision = 0x0002,
FrameCount = 0x0005,
PixelOrder = 0x0006,
ModeSelect = 0x0100,
ImageOrientation = 0x0101,
SoftwareReset = 0x0103,
GRP_ParamHold = 0x0104,
IntegrationHigh = 0x0202,
IntegrationLow = 0x0203,
AnalogGain = 0x0205,
DigitalGainHigh = 0x020E,
DigitalGainLow = 0x020F,
AE_TargetMean = 0x2101,
AE_MinMean = 0x2102,
ConvergeInThreshold = 0x2103,
ConvergeOutThreshold = 0x2104,
I2C_IdSelection = 0x3400,
I2C_Id = 0x3401,
PMU_ProgrammableFrameCount = 0x3020,
}
}
}