From 626be76cfc6bc02f12bee469e5565567e0e20ae0 Mon Sep 17 00:00:00 2001 From: Jussi Vestman Date: Mon, 28 Dec 2020 20:45:59 +0200 Subject: [PATCH] Added HC49 crystal generation, ATMega reset pull-up resistor and fixed tests --- arduino_generator.py | 41 ++++++++++++++++++++++++++--------------- controller.py | 4 +++- generator.py | 4 ++-- skimibowi.py | 14 ++++++++++++++ tests/arduino-nano.py | 18 +++++++++++------- tests/arduino-nano.yml | 2 ++ usb_uart_generator.py | 6 +++--- 7 files changed, 61 insertions(+), 28 deletions(-) diff --git a/arduino_generator.py b/arduino_generator.py index feec96b..a0a2256 100644 --- a/arduino_generator.py +++ b/arduino_generator.py @@ -29,6 +29,8 @@ def generate_atmega328p(args): """Generate ATmega328P subsystem to circuit""" + args['crystal'] = generate_atmega_crystal(args) + requirements.add(generate_r) return ''' U1 = Part('MCU_Microchip_ATmega', '{mcu}', footprint='{mcu_footprint}') @@ -36,7 +38,28 @@ def generate_atmega328p(args): U1['VCC'] += Net.fetch('+5V') U1['AVCC'] += Net.fetch('+5V') U1['GND'] += Net.fetch('GND') +U1['~RESET~/PC6'] & R('10k') & Net.fetch('{mcurail}') +{crystal} +# Serial communications +U1['PD1'] += Net.fetch('tx') +U1['PD0'] += Net.fetch('rx') + +# I2C +U1['PC4'] += Net.fetch('SDA') +U1['PC5'] += Net.fetch('SCL') +'''.format(**args) +def generate_atmega_crystal(args): + """Generate crystal for ATmega328P""" + if args['crystal_footprint'] == 'HC-49': + requirements.add(generate_c) + return ''' +# Crystal +ATMEGA_XTAL = Part('Device','Crystal', value="{crystal_frequency}",footprint='Crystal:Crystal_HC49-4H_Vertical') +U1['XTAL1/PB6'] & C('18pF') & ATMEGA_XTAL & C('18pF') & U1['XTAL2/PB7'] +'''.format(**args) + if args['crystal_footprint'] == 'CST': + return ''' # Crystal ATMEGA_XTAL = Part('Device','Resonator', footprint='Resonator_SMD_muRata_CSTxExxV-3Pin_3.0x1.1mm') U1['XTAL1/PB6'] += ATMEGA_XTAL[1] @@ -46,14 +69,6 @@ def generate_atmega328p(args): ATMEGA_XTAL_R = Part('Device', 'R', value='1M', footprint='{resistor_footprint}') U1['XTAL1/PB6'] += ATMEGA_XTAL_R[1] U1['XTAL2/PB7'] += ATMEGA_XTAL_R[2] - -# Serial communications -U1['PD1'] += Net.fetch('tx') -U1['PD0'] += Net.fetch('rx') - -# I2C -U1['PC4'] += Net.fetch('SDA') -U1['PC5'] += Net.fetch('SCL') '''.format(**args) @@ -109,10 +124,8 @@ def generate_arduino_reset_button(): def generate_arduino_ftdi_reset(args): """Generate connection to FTDI header reset""" - requirements.add(generate_r) requirements.add(generate_c) return ''' -U1['~RESET~/PC6'] & R('1k') & Net.fetch('{mcurail}') U1['~RESET~/PC6'] & C('100nF') & Net.fetch('RTS') '''.format(**args) @@ -140,7 +153,7 @@ def generate_arduino_nano_v3_board_footprint(): """Generate Arduino Nano V3 board layout footprint""" return ''' BOARD = Part('MCU_Module', 'Arduino_Nano_v3.x', footprint='Module:Arduino_Nano') -BOARD['RESET'] += U1['~RESET~/PC6'] +BOARD['~RESET'] += U1['~RESET~/PC6'] BOARD['+5V'] += Net.fetch('+5V') BOARD['3V3'] += Net.fetch('+3V3') BOARD['GND'] += Net.fetch('GND') @@ -149,8 +162,8 @@ def generate_arduino_nano_v3_board_footprint(): BOARD['A4'] += Net.fetch('SDA') BOARD['A5'] += Net.fetch('SCL') -BOARD['RX'] += Net.fetch('rx') -BOARD['TX'] += Net.fetch('tx') +BOARD['D0/RX'] += Net.fetch('rx') +BOARD['D1/TX'] += Net.fetch('tx') ''' @@ -168,8 +181,6 @@ def generate_atmega_arduino_board_connections(): BOARD['A1'] += U1['PC1'] BOARD['A2'] += U1['PC2'] BOARD['A3'] += U1['PC3'] -BOARD['A4'] += U1['PC4'] -BOARD['A5'] += U1['PC5'] BOARD['D8'] += U1['PB0'] BOARD['D9'] += U1['PB1'] diff --git a/controller.py b/controller.py index f9f68ba..295c909 100644 --- a/controller.py +++ b/controller.py @@ -183,6 +183,8 @@ def fill_variables(wizard): 'onewire_connector': wizard.field('onewire_connector'), 'common_footprint': wizard.field('common_footprint'), 'transistor_footprint': wizard.field('transistor_footprint'), + 'crystal_footprint': wizard.field('crystal_footprint'), + 'crystal_frequency': wizard.field('crystal_frequency'), 'resistor_footprint': resistor_footprints[wizard.field('common_footprint')], 'capacitor_footprint': capacitor_footprints[wizard.field('common_footprint')], 'led_footprint': led_footprints[wizard.field('common_footprint')], @@ -225,7 +227,7 @@ def load_settings(wizard, settings_filename="settings.yml"): 'switch', 'reset', 'Flash button', 'Reset button', 'led', 'FTDI header', 'usb_connector', 'ina219', 'DS18B20', 'DS18B20U', 'usb_uart', 'common_footprint', 'board_footprint', 'regulator', 'onewire_connector', 'autoselect', 'hc12', 'generate_labels', - 'title', 'author', 'regulator_vin_bypass_cap', 'regulator_vout_bypass_cap', 'sh1106', 'si5351']: + 'title', 'author', 'regulator_vin_bypass_cap', 'regulator_vout_bypass_cap', 'sh1106', 'si5351', 'crystal_footprint', 'crystal_frequency']: if field in settings: wizard.setField(field, settings[field]) except: diff --git a/generator.py b/generator.py index 665b457..8c4def9 100644 --- a/generator.py +++ b/generator.py @@ -159,12 +159,12 @@ def generate(args): if args.get('board_footprint', False) == 'Arduino Uno R3': code += generate_arduino_uno_r3_board_footprint() - if args['mcu'] in ['ATmega328P', 'ATmega328P-AU', 'ATmega328P-MU']: + if args['mcu'] in ['ATmega328P-PU', 'ATmega328P-AU', 'ATmega328P-MU']: code += generate_atmega_arduino_board_connections() if args.get('board_footprint', False) == 'Arduino Nano': code += generate_arduino_nano_v3_board_footprint() - if args['mcu'] in ['ATmega328P', 'ATmega328P-AU', 'ATmega328P-MU']: + if args['mcu'] in ['ATmega328P-PU', 'ATmega328P-AU', 'ATmega328P-MU']: code += generate_atmega_arduino_board_connections() if args.get('board_footprint', False) == 'Adafruit Feather': diff --git a/skimibowi.py b/skimibowi.py index 66644f6..ef8bd2e 100644 --- a/skimibowi.py +++ b/skimibowi.py @@ -86,6 +86,9 @@ def __init__(self, parent=None): self.ftdi_header = QtWidgets.QCheckBox("FTDI header") self.led = QtWidgets.QCheckBox("Power-on led on GPIO0") self.icsp = QtWidgets.QCheckBox("ICSP header") + self.crystal_frequency_label = QtWidgets.QLabel("Crystal Frequency") + self.crystal_frequency = QIComboBox(self) + self.crystal_frequency.addItems(['10Mhz', '12MHz', '16MHz', '20MHz']) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.comboBox) layout.addWidget(self.resetButton) @@ -94,6 +97,8 @@ def __init__(self, parent=None): layout.addWidget(self.ftdi_header) layout.addWidget(self.led) layout.addWidget(self.icsp) + layout.addWidget(self.crystal_frequency_label) + layout.addWidget(self.crystal_frequency) self.registerField("mcu", self.comboBox, "currentText") self.registerField("reset", self.resetLine) self.registerField("Reset button", self.resetButton) @@ -101,6 +106,7 @@ def __init__(self, parent=None): self.registerField("FTDI header", self.ftdi_header) self.registerField("led", self.led) self.registerField("icsp", self.icsp) + self.registerField("crystal_frequency", self.crystal_frequency, "currentText") self.setLayout(layout) @@ -177,6 +183,12 @@ def __init__(self, parent=None): self.transistor_footprint.addItems(["THT", "SOT-223", "SOT-23"]) self.registerField('transistor_footprint', self.transistor_footprint, 'currentText') + self.crystal_footprint_label = QtWidgets.QLabel() + self.crystal_footprint_label.setText("Crystal footprint") + self.crystal_footprint = QIComboBox(self) + self.crystal_footprint.addItems(["HC-49", "CST"]) + self.registerField('crystal_footprint', self.crystal_footprint, 'currentText') + self.button_footprint_label = QtWidgets.QLabel() self.button_footprint_label.setText("Tactile button footprint") self.button_footprint = QIComboBox(self) @@ -195,6 +207,8 @@ def __init__(self, parent=None): layout.addWidget(self.common_footprint) layout.addWidget(self.transistor_footprint_label) layout.addWidget(self.transistor_footprint) + layout.addWidget(self.crystal_footprint_label) + layout.addWidget(self.crystal_footprint) layout.addWidget(self.button_footprint_label) layout.addWidget(self.button_footprint) layout.addWidget(self.board_footprint_label) diff --git a/tests/arduino-nano.py b/tests/arduino-nano.py index 820b77b..ed68ee8 100644 --- a/tests/arduino-nano.py +++ b/tests/arduino-nano.py @@ -31,6 +31,11 @@ from skidl import Part +def R(value): + """Creates default resistor footprint""" + return Part('Device', 'R', value=value, footprint='Resistor_SMD:R_1206_3216Metric') + + def Device(library, name, value=""): """Make part lookup and return the part with footprint set""" footprint = show(library, name).F2 @@ -54,6 +59,7 @@ def C(value): U1['VCC'] += Net.fetch('+5V') U1['AVCC'] += Net.fetch('+5V') U1['GND'] += Net.fetch('GND') +U1['~RESET~/PC6'] & R('10k') & Net.fetch('+5V') # Crystal ATMEGA_XTAL = Part('Device','Resonator', footprint='Resonator_SMD_muRata_CSTxExxV-3Pin_3.0x1.1mm') @@ -110,12 +116,12 @@ def C(value): FTDI230['3V3OUT'] += Net.fetch('+3V3') FTDI230['USBDM'] += Net.fetch('USBD-') FTDI230['USBDP'] += Net.fetch('USBD+') -FTDI230['DTR'] += Net.fetch('DTR') -FTDI230['RTS'] += Net.fetch('RTS') +FTDI230['~DTR'] += Net.fetch('DTR') +FTDI230['~RTS'] += Net.fetch('RTS') Net.fetch('GND') & C('100nF') & FTDI230['3V3OUT'] BOARD = Part('MCU_Module', 'Arduino_Nano_v3.x', footprint='Module:Arduino_Nano') -BOARD['RESET'] += U1['~RESET~/PC6'] +BOARD['~RESET'] += U1['~RESET~/PC6'] BOARD['+5V'] += Net.fetch('+5V') BOARD['3V3'] += Net.fetch('+3V3') BOARD['GND'] += Net.fetch('GND') @@ -124,8 +130,8 @@ def C(value): BOARD['A4'] += Net.fetch('SDA') BOARD['A5'] += Net.fetch('SCL') -BOARD['RX'] += Net.fetch('rx') -BOARD['TX'] += Net.fetch('tx') +BOARD['D0/RX'] += Net.fetch('rx') +BOARD['D1/TX'] += Net.fetch('tx') BOARD['D2'] += U1['PD2'] BOARD['D3'] += U1['PD3'] @@ -138,8 +144,6 @@ def C(value): BOARD['A1'] += U1['PC1'] BOARD['A2'] += U1['PC2'] BOARD['A3'] += U1['PC3'] -BOARD['A4'] += U1['PC4'] -BOARD['A5'] += U1['PC5'] BOARD['D8'] += U1['PB0'] BOARD['D9'] += U1['PB1'] diff --git a/tests/arduino-nano.yml b/tests/arduino-nano.yml index a1be1df..f909aa3 100644 --- a/tests/arduino-nano.yml +++ b/tests/arduino-nano.yml @@ -37,3 +37,5 @@ usb_connector_footprint: footprint: USB_Mini-B_Lumberg_2486_01_Horizontal part: USB_B_Mini usb_uart: FT231 +crystal_footprint: CST +crystal_frequency: 16Mhz diff --git a/usb_uart_generator.py b/usb_uart_generator.py index fbff2ef..ffd3b65 100644 --- a/usb_uart_generator.py +++ b/usb_uart_generator.py @@ -42,8 +42,8 @@ def generate_ftdi230(args): FTDI230['3V3OUT'] += Net.fetch('+3V3') FTDI230['USBDM'] += Net.fetch('USBD-') FTDI230['USBDP'] += Net.fetch('USBD+') -FTDI230['DTR'] += Net.fetch('DTR') -FTDI230['RTS'] += Net.fetch('RTS') +FTDI230['~DTR'] += Net.fetch('DTR') +FTDI230['~RTS'] += Net.fetch('RTS') Net.fetch('GND') & C('100nF') & FTDI230['3V3OUT'] '''.format(**args) @@ -60,7 +60,7 @@ def generate_ftdi232rl(args): FTDI230['3V3OUT'] += Net.fetch('+3V3') FTDI230['USBD-'] += Net.fetch('USBD-') FTDI230['USBD+'] += Net.fetch('USBD+') -FTDI230['DTR'] += Net.fetch('DTR') +FTDI230['~DTR'] += Net.fetch('DTR') FTDI230['TEST'] += Net.fetch('GND') C_3V3 = Part('Device', 'C', value='100nF', footprint='{capacitor_footprint}') Net.fetch('GND') & C_3V3 & FTDI230['3V3OUT']