public static void Main(string[] args) { var pinCS0 = GpioPin.FromNumber(25); // Pin 22 (BCM 25) var pinCS1 = GpioPin.FromNumber(26); // Pin 37 (BCM 26) var pinRST = GpioPin.FromNumber(16); // Pin 36 (BCM 16) var spiSettings = new SpiConnectionSettings(busId: 0, chipSelectLine: 0); var gpioPinMap = new Dictionary <TargetChip, ChipPinConfig> { [TargetChip.Board0] = new ChipPinConfig(csPin: pinCS0, resetPin: pinRST), [TargetChip.Board1] = new ChipPinConfig(csPin: pinCS1, resetPin: pinRST), }; using (var spiDevice = new UnixSpiDevice(spiSettings)) using (var gpioController = new GpioController(PinNumberingScheme.Logical)) using (var ymf825Device = new NativeSpi(spiDevice, gpioController, gpioPinMap)) { var driver = new Ymf825Driver(ymf825Device); driver.EnableSectionMode(); Console.WriteLine("Software Reset"); driver.ResetSoftware(); SetupTones(driver); var index = 0; var score = new[] { 60, 62, 64, 65, 67, 69, 71, 72, 72, 74, 76, 77, 79, 81, 83, 84, 84, 83, 81, 79, 77, 76, 74, 72, 72, 71, 69, 67, 65, 64, 62, 60 }; while (true) { const int noteOnTime = 250; const int sleepTime = 0; NoteOn(driver, score[index]); Thread.Sleep(noteOnTime); NoteOff(driver); Thread.Sleep(sleepTime); if (Console.KeyAvailable) { break; } index++; if (index >= score.Length) { index = 0; } } driver.ResetHardware(); } }
private void ConnectDevice() { DeviceInfo = Spi.GetDeviceInfoList()[toolStripComboBox_deviceList.SelectedIndex]; ymf825 = new CbwYmf825Bb(toolStripComboBox_deviceList.SelectedIndex); Driver = new Ymf825Driver(ymf825); ymf825.DataWrote += (sender, args) => { registerMap.SetData(args.Address, args.Data); }; ymf825.DataBurstWrote += (sender, args) => { if (args.Data.Count <= 0) { return; } if (args.Address == 0x07) { registerMap.SetData(args.Address, args.Data.Last()); var toneNumber = args.Data[0] - 0x80; if (toneNumber < 0 || toneNumber > 16 || args.Data.Count < toneNumber * 30 + 5) { Console.WriteLine($"Invalid BurstWrite Data - Tone Number: {toneNumber}, Data Size: {args.Data.Count} (required {toneNumber * 30 + 5})"); return; } for (var i = 0; i < toneNumber; i++) { for (var j = 0; j < 30; j++) { toneParameterRegisterMap[i].SetData(j, args.Data[i * 30 + j + 1]); } } } else if (args.Address >= 0x20 || args.Address <= 0x22) { var eq = args.Address - 0x20; if (args.Data.Count < 5) { return; } for (var i = 0; i < 5; i++) { registerMap.SetData(0x23 + 3 * eq + i, args.Data[i]); } } }; SpiConnected = true; Driver.ResetHardware(); Driver.ResetSoftware(); Connected?.Invoke(this, new EventArgs()); }