summaryrefslogtreecommitdiffstatshomepage
path: root/ports/stm32/boards/make-pins.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-28 16:13:21 +1100
committerDamien George <damien.p.george@gmail.com>2018-03-28 16:29:50 +1100
commit2dca693c24f9bcadb1e06113848fff620d8088dd (patch)
tree8727b96ba401e79146d2e9bfcfed725cb988f6fb /ports/stm32/boards/make-pins.py
parentcf1d6df05acc22b641fb97de6a87b100b4fcfcb1 (diff)
downloadmicropython-2dca693c24f9bcadb1e06113848fff620d8088dd.tar.gz
micropython-2dca693c24f9bcadb1e06113848fff620d8088dd.zip
stm32: Change pin_X and pyb_pin_X identifiers to be pointers to objects.
Rather than pin objects themselves. The actual object is now pin_X_obj and defines are provided so that pin_X is &pin_X_obj. This makes it so that code that uses pin objects doesn't need to know if they are literals or objects (that need pointers taken) or something else. They are just entities that can be passed to the map_hal_pin_xxx functions. This mirrors how the core handles constant objects (eg mp_const_none which is &mp_const_none_obj) and allows for the possibility of different implementations of the pin layer. For example, prior to this patch there was the following: extern const pin_obj_t pin_A0; #define pyb_pin_X1 pin_A0 ... mp_hal_pin_high(&pin_A0); and now there is: extern const pin_obj_t pin_A0_obj; #define pin_A0 (&pin_A0_obj) #define pyb_pin_X1 pin_A0 ... mp_hal_pin_high(pin_A0); This patch should have minimal effect on board configuration files. The only change that may be needed is if a board has .c files that configure pins.
Diffstat (limited to 'ports/stm32/boards/make-pins.py')
-rwxr-xr-xports/stm32/boards/make-pins.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py
index 7db174114a..c9f6516f1c 100755
--- a/ports/stm32/boards/make-pins.py
+++ b/ports/stm32/boards/make-pins.py
@@ -207,18 +207,18 @@ class Pin(object):
print("// ", end='')
print('};')
print('')
- print('const pin_obj_t pin_{:s} = PIN({:s}, {:d}, {:s}, {:s}, {:d});'.format(
+ print('const pin_obj_t pin_{:s}_obj = PIN({:s}, {:d}, {:s}, {:s}, {:d});'.format(
self.cpu_pin_name(), self.port_letter(), self.pin,
self.alt_fn_name(null_if_0=True),
self.adc_num_str(), self.adc_channel))
print('')
def print_header(self, hdr_file):
- hdr_file.write('extern const pin_obj_t pin_{:s};\n'.
- format(self.cpu_pin_name()))
+ n = self.cpu_pin_name()
+ hdr_file.write('extern const pin_obj_t pin_{:s}_obj;\n'.format(n))
+ hdr_file.write('#define pin_{:s} (&pin_{:s}_obj)\n'.format(n, n))
if self.alt_fn_count > 0:
- hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.
- format(self.cpu_pin_name()))
+ hdr_file.write('extern const pin_af_obj_t pin_{:s}_af[];\n'.format(n))
def qstr_list(self):
result = []
@@ -287,7 +287,7 @@ class Pins(object):
for named_pin in named_pins:
pin = named_pin.pin()
if pin.is_board_pin():
- print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}) }},'.format(named_pin.name(), pin.cpu_pin_name()))
+ print(' {{ MP_ROM_QSTR(MP_QSTR_{:s}), MP_ROM_PTR(&pin_{:s}_obj) }},'.format(named_pin.name(), pin.cpu_pin_name()))
print('};')
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
@@ -311,7 +311,7 @@ class Pins(object):
pin = named_pin.pin()
if (pin.is_board_pin() and
(pin.adc_num & (1 << (adc_num - 1))) and (pin.adc_channel == channel)):
- print(' &pin_{:s}, // {:d}'.format(pin.cpu_pin_name(), channel))
+ print(' &pin_{:s}_obj, // {:d}'.format(pin.cpu_pin_name(), channel))
adc_found = True
break
if not adc_found: