forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ports/psoc6: First level changes to initiate make-pins script support.
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
- Loading branch information
1 parent
6aa2436
commit 9c4aef0
Showing
6 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TESTPort,,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF14,AF15, | ||
,,SYS,TIM1/2,TIM3/4/5,TIM8/9/10/11,I2C1/2/3,SPI1/SPI2/I2S2/I2S2ext,SPI3/I2Sext/I2S3,USART1/2/3/I2S3ext,UART4/5/USART6,CAN1/CAN2/TIM12/13/14,OTG_FS/OTG_HS,ETH,FSMC/SDIO/OTG_FS,DCMI,,,ADC | ||
PortA,PA0,,TIM2_CH1/TIM2_ETR,TIM5_CH1,TIM8_ETR,,,,USART2_CTS,UART4_TX,,,ETH_MII_CRS,,,,EVENTOUT,ADC123_IN0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
from __future__ import print_function | ||
|
||
import argparse | ||
import sys | ||
import csv | ||
|
||
class Pin: | ||
"""Holds the information associated with a pin.""" | ||
|
||
def __init__(self): | ||
def __init__(self, pin): | ||
self.port = port | ||
self.pin = pin | ||
self.alt_fn = [] | ||
self.alt_fn_count = 0 | ||
|
||
class Pins(object): | ||
def _init_(self): | ||
self.cpu_pins = [] # list of NamedPin objects | ||
self.board_pins = [] # list of NamedPin objects | ||
|
||
def find_pin(self, cpu_pin_name): | ||
for named_pin in self.cpu_pins: | ||
pin = named_pin.pin() | ||
if pin.cpu_pin_name() == cpu_pin_name: | ||
return pin | ||
|
||
def print_named(self, label, named_pins): | ||
print( | ||
"STATIC const mp_rom_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{".format(label) | ||
) | ||
for named_pin in named_pins: | ||
pin = named_pin.pin() | ||
if pin.is_board_pin() and not named_pin.is_hidden(): | ||
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 | ||
) | ||
) | ||
|
||
def print(self): | ||
for named_pin in self.cpu_pins: | ||
pin = named_pin.pin() | ||
if pin.is_board_pin(): | ||
pin.print() | ||
self.print_named("cpu", self.cpu_pins) | ||
print("") | ||
self.print_named("board", self.board_pins) | ||
|
||
|
||
def parse_af_file(self, filename, pinname_col, af_col): | ||
with open(filename, "r") as csvfile: | ||
rows = csv.reader(csvfile) | ||
for row in rows: | ||
try: | ||
(port_num, pin_num) = parse_port_pin(row[pinname_col]) | ||
except: | ||
continue | ||
pin = Pin(port_num, pin_num) | ||
for af_idx in range(af_col, len(row)): | ||
if af_idx < af_col + 16: | ||
pin.parse_af(af_idx - af_col, row[af_idx]) | ||
elif af_idx == af_col + 16: | ||
pin.parse_adc(row[af_idx]) | ||
self.cpu_pins.append(NamedPin(pin.cpu_pin_name(), pin)) | ||
|
||
|
||
def parse_board_file(self, filename): | ||
with open(filename, "r") as csvfile: | ||
rows = csv.reader(csvfile) | ||
for row in rows: | ||
try: | ||
board_pin_name = row[0] | ||
cpu_pin_name = row[1] | ||
except: | ||
continue | ||
pin = self.find_pin(cpu_pin_name) | ||
if pin: | ||
pin.set_is_board_pin() | ||
self.board_pins.append(NamedPin(board_pin_name, pin)) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
prog="make-pins.py", | ||
usage="%(prog)s [options] [command]", | ||
description="Generate board specific pin file", | ||
) | ||
|
||
parser.add_argument( | ||
"-a", | ||
"--af", | ||
dest="af_filename", | ||
help="Specifies the alternate function file for the chip", | ||
default="cy8c62xa_af.csv", | ||
) | ||
|
||
parser.add_argument( | ||
"-b", "--board", dest="board_filename", help="Specifies the board file", default="pins.csv" | ||
) | ||
|
||
parser.add_argument( | ||
"-q", | ||
"--qstr", | ||
dest="qstr_filename", | ||
help="Specifies name of generated qstr header file", | ||
default="build/pins_qstr.h", | ||
) | ||
|
||
parser.add_argument( | ||
"-r", | ||
"--hdr", | ||
dest="hdr_filename", | ||
help="Specifies name of generated pin header file", | ||
default="build/pins.h", | ||
) | ||
args = parser.parse_args(sys.argv[1:]) | ||
|
||
pins = Pins() | ||
|
||
print("// This file was automatically generated by make-pins.py") | ||
print("//") | ||
|
||
if args.af_filename: | ||
print("// --af {:s}".format(args.af_filename)) | ||
pins.parse_af_file(args.af_filename, 1, 2) | ||
|
||
'''if args.board_filename: | ||
print("// --board {:s}".format(args.board_filename)) | ||
pins.parse_board_file(args.board_filename) | ||
if args.prefix_filename: | ||
print("// --prefix {:s}".format(args.prefix_filename)) | ||
print("") | ||
with open(args.prefix_filename, "r") as prefix_file: | ||
print(prefix_file.read())''' | ||
|
||
#pins.print() | ||
#pins.print_header(args.hdr_filename) | ||
#pins.print_qstr(args.qstr_filename) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
P0_0, P0_0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// ra_pin_prefix.c becomes the initial portion of the generated pins file. | ||
|
||
#include <stdio.h> | ||
|
||
#include "py/obj.h" | ||
#include "py/mphal.h" | ||
#include "pins.h" | ||
|
||
#define PIN(p_name, p_pin, p_ad) \ | ||
{ \ | ||
{ &machine_pin_type }, \ | ||
.name = MP_QSTR_##p_name, \ | ||
.pin = p_pin, \ | ||
.ad = p_ad, \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters