diff --git a/src/devices/lgt8f328p/lgt8f328pNano.js b/src/devices/lgt8f328p/lgt8f328pNano.js new file mode 100644 index 00000000000..7b9e13cf1f7 --- /dev/null +++ b/src/devices/lgt8f328p/lgt8f328pNano.js @@ -0,0 +1,142 @@ +/** + * Arduino Nano + * + * @overview Compared to the Arduino Uno, this control board use CH340 as + * use to uart chip, uese oldbootloader to flash the firmware, and there are + * more A6 and A7 pin options. + */ +const OpenBlockArduinoUnoDevice = require('../arduinoUno/arduinoUno'); + +const ArduinoPeripheral = require('../common/arduino-peripheral'); + +/** + * The list of USB device filters. + * @readonly + */ +const PNPID_LIST = [ + 'USB\\VID_04D9&PID_B534' +]; + +/** + * Configuration of serialport + * @readonly + */ +const SERIAL_CONFIG = { + baudRate: 57600, + dataBits: 8, + stopBits: 1 +}; + +/** + * Configuration for arduino-cli. + * @readonly + */ +const DIVECE_OPT = { + type: 'arduino', + fqbn: 'lgt8fx:avr:328', + firmware: 'lgt8f328pNano.hex' +}; + +const Pins = { + D0: '0', + D1: '1', + D2: '2', + D3: '3', + D4: '4', + D5: '5', + D6: '6', + D7: '7', + D8: '8', + D9: '9', + D10: '10', + D11: '11', + D12: '12', + D13: '13', + A0: 'A0', + A1: 'A1', + A2: 'A2', + A3: 'A3', + A4: 'A4', + A5: 'A5', + A6: 'A6', + A7: 'A7' +}; + +/** + * Manage communication with a Arduino Nano peripheral over a OpenBlock Link client socket. + */ +class Lgt8f328pNano extends ArduinoPeripheral{ + /** + * Construct a Arduino communication object. + * @param {Runtime} runtime - the OpenBlock runtime + * @param {string} deviceId - the id of the extension + * @param {string} originalDeviceId - the original id of the peripheral, like xxx_arduinoUno + */ + constructor (runtime, deviceId, originalDeviceId) { + super(runtime, deviceId, originalDeviceId, PNPID_LIST, SERIAL_CONFIG, DIVECE_OPT); + } +} + +/** + * OpenBlock blocks to interact with a Arduino Nano Ultra peripheral. + */ +class OpenBlockLgt8f328pNanoDevice extends OpenBlockArduinoUnoDevice{ + + /** + * @return {string} - the ID of this extension. + */ + get DEVICE_ID () { + return 'lgt8f328pNano'; + } + + get ANALOG_PINS_MENU () { + return [ + { + text: 'A0', + value: Pins.A0 + }, + { + text: 'A1', + value: Pins.A1 + }, + { + text: 'A2', + value: Pins.A2 + }, + { + text: 'A3', + value: Pins.A3 + }, + { + text: 'A4', + value: Pins.A4 + }, + { + text: 'A5', + value: Pins.A5 + }, + { + text: 'A6', + value: Pins.A6 + }, + { + text: 'A7', + value: Pins.A7 + } + ]; + } + + /** + * Construct a set of Arduino blocks. + * @param {Runtime} runtime - the OpenBlock runtime. + * @param {string} originalDeviceId - the original id of the peripheral, like xxx_arduinoUno + */ + constructor (runtime, originalDeviceId) { + super(runtime, originalDeviceId); + + // Create a new Arduino Nano peripheral instance + this._peripheral = new Lgt8f328pNano(this.runtime, this.DEVICE_ID, originalDeviceId); + } +} + +module.exports = OpenBlockLgt8f328pNanoDevice; \ No newline at end of file diff --git a/src/extension-support/extension-manager.js b/src/extension-support/extension-manager.js index 338b82fa1f3..5bcd96709c0 100644 --- a/src/extension-support/extension-manager.js +++ b/src/extension-support/extension-manager.js @@ -53,7 +53,8 @@ const builtinDevices = { arduinoRaspberryPiPico: () => require('../devices/arduinoRaspberryPiPico/arduinoRaspberryPiPico'), // Microbit microbit: () => require('../devices/microbit/microbit'), - microbitV2: () => require('../devices/microbit/microbitV2') + microbitV2: () => require('../devices/microbit/microbitV2'), + lgt8f328pNano: () => require('../devices/lgt8f328p/lgt8f328pNano') // TODO: transform these to device extension. // wedo2: () => require('../extensions/scratch3_wedo2'),