|
3 | 3 | # |
4 | 4 | # Copyright (c) 2016-2018, Niklas Hauser |
5 | 5 | # Copyright (c) 2017, Fabian Greif |
| 6 | +# Copyright (c) 2020, Christopher Durand |
6 | 7 | # |
7 | 8 | # This file is part of the modm project. |
8 | 9 | # |
@@ -123,6 +124,44 @@ def validate_alternate_functions(driver, env): |
123 | 124 | if not success: |
124 | 125 | env.log.debug("Gpio signal validation failed!") |
125 | 126 |
|
| 127 | +def is_remap_pin(driver, pin, port): |
| 128 | + """ |
| 129 | + For the STM32F0/G0 series |
| 130 | + ------------------------- |
| 131 | + Some chips exist where gpios can be multiplexed on some package pins |
| 132 | + """ |
| 133 | + package_pins = driver["package"][0]["pin"] |
| 134 | + pin_name = 'P{}{}'.format(port.upper(), pin) |
| 135 | + package_pin = next(pin for pin in package_pins if pin['name'].startswith(pin_name)) |
| 136 | + variant = package_pin.get('variant', None) |
| 137 | + if variant is not None and 'remap' in variant: |
| 138 | + return True |
| 139 | + else: |
| 140 | + position = package_pin["position"] |
| 141 | + def is_other_mapping(p): |
| 142 | + variant = p.get('variant', None) |
| 143 | + return (p['position'] == position) and variant is not None and 'remap' in variant |
| 144 | + return any(pin for pin in package_pins if is_other_mapping(pin)) |
| 145 | + |
| 146 | +def get_remap_command(family, pin, port): |
| 147 | + if family not in ["f0", "g0"]: |
| 148 | + raise ValidateException("Remapped package pins only supported for F0 and G0") |
| 149 | + if (port != 'a' or pin not in ["9","10","11","12"]): |
| 150 | + raise ValidateException("Only Pins PA9/PA10/PA11/PA12 can be remapped") |
| 151 | + |
| 152 | + reg = 'SYSCFG->CFGR1' |
| 153 | + value = { |
| 154 | + ('f0', '9') : ('SYSCFG_CFGR1_PA11_PA12_RMP', False), |
| 155 | + ('f0', '10') : ('SYSCFG_CFGR1_PA11_PA12_RMP', False), |
| 156 | + ('f0', '11') : ('SYSCFG_CFGR1_PA11_PA12_RMP', True), |
| 157 | + ('f0', '12') : ('SYSCFG_CFGR1_PA11_PA12_RMP', True), |
| 158 | + ('g0', '9') : ('SYSCFG_CFGR1_PA11_RMP', True), |
| 159 | + ('g0', '10') : ('SYSCFG_CFGR1_PA12_RMP', True), |
| 160 | + ('g0', '11') : ('SYSCFG_CFGR1_PA11_RMP', False), |
| 161 | + ('g0', '12') : ('SYSCFG_CFGR1_PA12_RMP', False) |
| 162 | + } |
| 163 | + return (reg,) + value[(family, pin)] |
| 164 | + |
126 | 165 | bprops = {} |
127 | 166 |
|
128 | 167 | # ----------------------------------------------------------------------------- |
@@ -257,6 +296,10 @@ def build(env): |
257 | 296 |
|
258 | 297 | for gpio in driver["gpio"]: |
259 | 298 | po, pi = gpio["port"], gpio["pin"] |
| 299 | + properties["remap_pin"] = is_remap_pin(driver, pi, po) |
| 300 | + if properties["remap_pin"]: |
| 301 | + family = device.identifier["family"] |
| 302 | + (properties["remap_reg"],properties["remap_value"],properties["remap_set"]) = get_remap_command(family, pi, po) |
260 | 303 | properties.update(bprops[po + pi]) |
261 | 304 | header_name = "gpio_{}{}.hpp".format(po.upper(), pi) |
262 | 305 | env.template(gpio_source, header_name, filters={ "to_adc_channel" : lambda name : "".join(filter(str.isdigit, name)) }) |
|
0 commit comments