Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Tools: DFG: Add ability to automatically describe differences in GPIO…
Browse files Browse the repository at this point in the history
… AFs.

This requires only changes to the platform reader and writer, the core
merging code is unchanged.
  • Loading branch information
salkinium committed Dec 28, 2013
1 parent 148da85 commit 076ad72
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<driver type="uart" name="stm32" instances="1,2"/>
<driver type="gpio" name="stm32">
<gpio port="A" id="0">
<af device-name="051" device-size-id="6|8" id="1" peripheral="Uart2" name="Cts" type="in"/>
<af device-name="051" device-size-id="6|8" id="1" peripheral="Uart2" name="Cts" type="in"/>
<af id="2" peripheral="Timer2" name="Channel1"/>
<af id="2" peripheral="Timer2" name="ExternalTrigger" type="in"/>
<af peripheral="AdcC" name="Channel0" type="analog"/>
Expand Down
41 changes: 24 additions & 17 deletions tools/device_file_generator/stm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(self, file, logger=None):

gpios = []
self.addProperty('gpios', gpios)
gpio_afs = []
self.addProperty('gpio_afs', gpio_afs)
peripherals = []
self.addProperty('peripherals', peripherals)
modules = []
Expand Down Expand Up @@ -167,7 +169,9 @@ def __init__(self, file, logger=None):
name = name.split('/')[0]

gpio = {'port': name[1:2], 'id': name[2:]}
gpio_afs = []
gpios.append(gpio)

afs = []

for signal in [s.get('Name') for s in pin if s.get('Name') != 'GPIO']:
raw_names = signal.split('_')
Expand All @@ -187,7 +191,7 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

mapName = {'rx': 'miso', 'tx': 'mosi', 'ck': 'sck'}
if signal.startswith('USART') and name in mapName:
Expand All @@ -197,7 +201,7 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

elif signal.startswith('SPI'):
af = {'peripheral' : 'SpiMaster' + instance,
Expand All @@ -206,13 +210,13 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(dict(af))
afs.append(dict(af))
invertName = {'miso': 'somi', 'mosi': 'simo', 'nss': 'nss', 'sck': 'sck'}
af.update({ 'peripheral' : 'SpiSlave' + instance,
'name': invertName[name].capitalize()})
if mode:
af.update({'type': invertMode[nameToMode[name]]})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('CAN'):
af = {'peripheral' : 'Can' + instance,
Expand All @@ -221,7 +225,7 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('I2C'):
if name in ['scl', 'sda']:
Expand All @@ -231,7 +235,7 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('TIM'):
for tname in raw_names[1:]:
Expand All @@ -249,28 +253,28 @@ def __init__(self, file, logger=None):
af.update({'type': output_type})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('ADC'):
if 'exti' not in name:
af = {'peripheral' : 'Adc' + instance,
'name': name.replace('in', 'Channel').capitalize(),
'type': 'analog'}
gpio_afs.append(af)
afs.append(af)

if signal.startswith('SYS'):
if 'mco' in name:
af = {'peripheral' : signal.replace('SYS', '').replace('_', ''),
'type': 'out',
'id': '0'}
gpio_afs.append(af)
afs.append(af)

if signal.startswith('OTG_FS') and raw_names[2] in ['DM', 'DP']:
af = {'peripheral' : 'Usb',
'name': raw_names[2].capitalize()}
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('USB'):
af = {'peripheral' : 'Usb',
Expand All @@ -279,21 +283,24 @@ def __init__(self, file, logger=None):
af.update({'type': mode})
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

if signal.startswith('FSMC_NOR_MUX_'):
af = {'peripheral' : 'Fsmc',
'name': raw_names[3].capitalize().replace('Da','D')}
if af_id:
af.update({'id': af_id})
gpio_afs.append(af)
afs.append(af)

# sort after key id and then add all without ids
gpio['af'] = [a for a in gpio_afs if 'id' in a]
gpio['af'].sort(key=lambda k: (int(k['id']), k['peripheral']))
gpio['af'].extend([a for a in gpio_afs if 'id' not in a])
sorted_afs = [a for a in afs if 'id' in a]
sorted_afs.sort(key=lambda k: (int(k['id']), k['peripheral']))
sorted_afs.extend([a for a in afs if 'id' not in a])

gpios.append(gpio)
for af in sorted_afs:
af['gpio_port'] = gpio['port']
af['gpio_id'] = gpio['id']
gpio_afs.append(af)

def _modulesToString(self):
string = ""
Expand Down
30 changes: 20 additions & 10 deletions tools/device_file_generator/stm_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,28 @@ def addGpioToNode(self, node):
gpios = prop.value

for id in prop.ids.differenceFromIds(self.device.ids):
dict = self._getAttributeDictionaryFromId(id)
attr = self._getAttributeDictionaryFromId(id)
for gpio in gpios:
gpio_child = driver.addChild('gpio')
gpio_child.setAttributes(dict)
for name in ['port', 'id']:
if name in gpio:
gpio_child.setAttribute(name, gpio[name])
for af in gpio['af']:
af_child = gpio_child.addChild('af')
for id in ['id', 'peripheral', 'name', 'type']:
if id in af:
af_child.setAttribute(id, af[id])
gpio_child.setAttributes(attr)
gpio_child.setAttributes(gpio)
# search for alternate functions
matches = []
for af_property in self.device.getProperty('gpio_afs').values:
for af in af_property.value:
if af['gpio_port'] == gpio['port'] and af['gpio_id'] == gpio['id']:
differences = af_property.ids.differenceFromIds(prop.ids)
matches.append({'af': dict(af), 'differences': differences})
print matches
for af_dict in matches:
for af_id in af_dict['differences']:
af_attr = self._getAttributeDictionaryFromId(af_id)
af_child = gpio_child.addChild('af')
af_child.setAttributes(af_attr)
for key in ['id', 'peripheral', 'name', 'type'] :
if key in af_dict['af']:
af_child.setAttribute(key, af_dict['af'][key])
gpio_child.sort(key=lambda k : (int(k.get('id') or 1e6), k.get('peripheral')))
# sort the node children by port and id
driver.sort(key=lambda k : (k.get('port'), int(k.get('id'))) )

Expand Down

0 comments on commit 076ad72

Please sign in to comment.