public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, FPGA.OutputSignal <bool> Bank3, // WS2812 FPGA.OutputSignal <bool> DOUT, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD // SERVO IO is generated inside handlers ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); QuokkaBoard.OutputBank(Bank3); IsAlive.Blink(LED1); DeviceControl(DOUT, RXD, TXD); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { bool internalTXD = true; FPGA.Config.Link(internalTXD, TXD); IsAlive.Blink(LED1); Sequential handler = () => { for (byte b = 0; b < 10; b++) { UART.RegisteredWrite(115200, b, out internalTXD); } UART.RegisteredWrite(115200, 255, out internalTXD); }; FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { IsAlive.Blink(LED1); Sequential handler = () => { byte[] buff = new byte[11]; for (byte b = 0; b < 10; b++) { buff[b] = b; } buff[10] = 255; for (byte i = 0; i < buff.Length; i++) { byte data = 0; // TODO: initializer from memory not supported yet data = buff[i]; UART.Write(115200, data, TXD); } }; FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler); }
public static async Task Aggregator( // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, // blinker FPGA.OutputSignal <bool> LED1, // WS2812 FPGA.OutputSignal <bool> DOUT ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); IsAlive.Blink(LED1); bool internalDOUT = false; FPGA.Config.Link(internalDOUT, DOUT); byte state = 0; eCellType[] fieldMatrix = new eCellType[64]; Sequential handler = () => { state++; FieldMatrix.Reset(fieldMatrix); switch (state) { case 1: fieldMatrix[0] = eCellType.RedCross; fieldMatrix[63] = eCellType.GreenCross; break; case 2: FieldMatrix.DrawCross(fieldMatrix, eCellType.GreenCross); break; case 3: FieldMatrix.DrawCross(fieldMatrix, eCellType.RedCross); break; case 4: Position head = new Position(), tail = new Position(); FieldMatrix.Seed(fieldMatrix, head, tail); break; default: state = 0; break; } Graphics.DrawFieldMatrix(1, fieldMatrix, out internalDOUT); }; FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, FPGA.OutputSignal <bool> LED2, FPGA.OutputSignal <bool> LED3, FPGA.OutputSignal <bool> LED4 ) { IsAlive.Blink(LED1); IsAlive.Blink(LED2); IsAlive.Blink(LED3); IsAlive.Blink(LED4); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // keypad FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, // WS2812 FPGA.OutputSignal <bool> DOUT, // ADC FPGA.OutputSignal <bool> ADC1NCS, FPGA.OutputSignal <bool> ADC1SLCK, FPGA.OutputSignal <bool> ADC1DIN, FPGA.InputSignal <bool> ADC1DOUT, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); GameControlsState controlsState = new GameControlsState(); IsAlive.Blink(LED1); Peripherals.GameControls( ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT, K7, K6, K5, K4, K3, K2, K1, K0, controlsState); SnakeControl( controlsState, DOUT, TXD); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, FPGA.OutputSignal <bool> LED2, // keypad FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, // ADC FPGA.OutputSignal <bool> ADC1NCS, FPGA.OutputSignal <bool> ADC1SLCK, FPGA.OutputSignal <bool> ADC1DIN, FPGA.InputSignal <bool> ADC1DOUT, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { IsAlive.Blink(LED1); QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); KeysDTO controlsState = new KeysDTO(); Peripherals.Controls( ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT, K7, K6, K5, K4, K3, K2, K1, K0, ref controlsState); ConfigureReporting(controlsState, TXD, LED2); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { IsAlive.Blink(LED1); SnakeDBG dbg = new SnakeDBG(); Sequential handler = () => { dbg.C1++; JSON.SerializeToUART(ref dbg, TXD); }; FPGA.Config.OnStartup(handler); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // keypad FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, // WS2812 FPGA.OutputSignal <bool> DOUT ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); IndicatorsControlsState controlsState = new IndicatorsControlsState(); IsAlive.Blink(LED1); Peripherals.IndicatorsControls( K7, K6, K5, K4, K3, K2, K1, K0, controlsState); LEDControl(controlsState); IndicatorsControl( controlsState, DOUT); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, FPGA.OutputSignal <bool> Bank5, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); QuokkaBoard.OutputBank(Bank5); IsAlive.Blink(LED1); bool internalTXD = true; FPGA.Config.Link(internalTXD, TXD); const int servosCount = 3; byte[] servosData = new byte[servosCount]; Sequential servoHandler = () => { uint instanceId = FPGA.Config.InstanceId(); var servoOutputPin = new FPGA.OutputSignal <bool>(); byte value = 0; bool servoOutput = false; byte requestValue = 0; FPGA.Config.Link(servoOutput, servoOutputPin); while (true) { requestValue = servosData[instanceId]; if (requestValue != value) { if (requestValue < value) { value--; } else { value++; } } MG996R.Write(value, out servoOutput); } }; FPGA.Config.OnStartup(servoHandler, servosCount); Sequential readHandler = () => { byte data = 0; byte counter = 0; while (true) { data = UART.Read(115200, RXD); if (data == 255 || counter == 255) { // begin of packet or overflow counter = 0; } else { if (counter < servosCount) { servosData[counter] = data; } counter++; } } }; FPGA.Config.OnStartup(readHandler); }
public static async Task Aggregator( // banks FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, // blinker FPGA.OutputSignal <bool> LED1, FPGA.OutputSignal <bool> LED2, FPGA.OutputSignal <bool> LED3, FPGA.OutputSignal <bool> LED4, // WS2812 FPGA.OutputSignal <bool> DOUT, // keypad FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, // ADC FPGA.OutputSignal <bool> ADC1NCS, FPGA.OutputSignal <bool> ADC1SLCK, FPGA.OutputSignal <bool> ADC1DIN, FPGA.InputSignal <bool> ADC1DOUT, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); GameControlsState controlsState = new GameControlsState(); IsAlive.Blink(LED1); IsAlive.Blink(LED2); IsAlive.Blink(LED3); IsAlive.Blink(LED4); Peripherals.GameControls( ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT, K7, K6, K5, K4, K3, K2, K1, K0, controlsState); LEDControl(controlsState.keyCode, DOUT); byte data = 0; Sequential handler = () => { UART.Write(115200, data, TXD); data++; }; FPGA.Config.OnTimer(TimeSpan.FromSeconds(1), handler); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // IO banks for Quokka board, not needed for another boards FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, FPGA.OutputSignal <bool> Bank5, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); QuokkaBoard.OutputBank(Bank5); IsAlive.Blink(LED1); bool internalTXD = true; FPGA.Config.Link(internalTXD, TXD); const int servosCount = 3; byte[] servosData = new byte[servosCount]; Sequential servoHandler = () => { uint instanceId = FPGA.Config.InstanceId(); var servoOutputPin = new FPGA.OutputSignal <bool>(); byte value = 0; bool servoOutput = false; byte requestValue = 0; FPGA.Config.Link(servoOutput, servoOutputPin); while (true) { requestValue = servosData[instanceId]; if (requestValue != value) { if (requestValue < value) { value--; } else { value++; } } MG996R.Write(value, out servoOutput); } }; FPGA.Config.OnStartup(servoHandler, servosCount); Sequential readHandler = () => { byte counter = 0; byte step = 5; while (true) { while (counter < 180) { servosData[0] = counter; servosData[1] = counter; servosData[2] = counter; counter += step; FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(100)); } while (counter > 0) { servosData[0] = counter; servosData[1] = counter; servosData[2] = counter; counter -= step; FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(100)); } } }; FPGA.Config.OnStartup(readHandler); }
public static async Task Aggregator( // blinker FPGA.OutputSignal <bool> LED1, // IO banks for Quokka board, not needed for another boards FPGA.OutputSignal <bool> Bank1, FPGA.OutputSignal <bool> Bank2, FPGA.OutputSignal <bool> Bank5, // ADC FPGA.OutputSignal <bool> ADC1NCS, FPGA.OutputSignal <bool> ADC1SLCK, FPGA.OutputSignal <bool> ADC1DIN, FPGA.InputSignal <bool> ADC1DOUT, // UART FPGA.InputSignal <bool> RXD, FPGA.OutputSignal <bool> TXD ) { QuokkaBoard.OutputBank(Bank1); QuokkaBoard.InputBank(Bank2); QuokkaBoard.OutputBank(Bank5); IsAlive.Blink(LED1); bool internalTXD = true; FPGA.Config.Link(internalTXD, TXD); const int servosCount = 4; byte[] servosData = new byte[servosCount] { 90, // main panel starts lookup up 90, // main panel starts lookup up 50, // sensor panel starts at beginning of measurement cycle 50, // sensor panel starts at beginning of measurement cycle }; object servosLock = new object(); bool autoScan = true; Sequential servoHandler = () => { uint instanceId = FPGA.Config.InstanceId(); var servoOutputPin = new FPGA.OutputSignal <bool>(); byte value = 0; bool servoOutput = false; byte requestValue = 0; FPGA.Config.Link(servoOutput, servoOutputPin); while (true) { requestValue = servosData[instanceId]; if (FPGA.Config.InstanceId() <= 1) { // large panel moves with smoothing if (requestValue != value) { if (requestValue < value) { value--; } else { value++; } } } else { value = requestValue; } MG996R.Write(value, out servoOutput); } }; FPGA.Config.OnStartup(servoHandler, servosCount); Sequential autoScanHandler = () => { while (true) { if (!autoScan) { continue; } byte s2Delta = 5; sbyte s3Delta = 5; ushort maxChannel1Value = 0; byte s2Max = 0, s3Max = 0; // reset sensor panel to center for (byte i = 2; i < servosCount; i++) { servosData[i] = 90; } FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(50)); byte s3 = 50; for (byte s2 = 50; s2 <= 130; s2 += s2Delta) { servosData[2] = s2; while (s3 >= 50 && s3 <= 130) { servosData[3] = s3; // TODO: barrier sync all servo handlers FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(50)); ushort adcChannel1Value = 0, adcChannel2Value = 0; ADC102S021.Read(out adcChannel1Value, out adcChannel2Value, ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT); if (adcChannel1Value > maxChannel1Value) { s2Max = s2; s3Max = s3; maxChannel1Value = adcChannel1Value; byte[] buff = new byte[3]; byte tmp; buff[0] = 255; buff[1] = s2Max; buff[2] = s3Max; for (byte i = 0; i < buff.Length; i++) { tmp = buff[i]; UART.Write(115200, tmp, internalTXD); } } s3 = (byte)(s3 + s3Delta); } s3Delta = (sbyte)(-s3Delta); s3 = (byte)(s3 + s3Delta); // compensate for overshoot } servosData[1] = (byte)(180 - s2Max); // should be mirrored around 90 as servo is backwards servosData[0] = s3Max; // same value FPGA.Runtime.Delay(TimeSpan.FromMilliseconds(1000)); } }; FPGA.Config.OnStartup(autoScanHandler); SetServos request = new SetServos(); FPGA.Signal <bool> requestDeserialized = new FPGA.Signal <bool>(); JSON.DeserializeFromUART <SetServos>(ref request, RXD, requestDeserialized); Sequential onRequest = () => { autoScan = request.autoRun == 0 ? false : true; servosData[0] = request.s0; servosData[1] = request.s1; servosData[2] = request.s2; servosData[3] = request.s3; }; FPGA.Config.OnSignal(requestDeserialized, onRequest); }