Skip to content

Commit

Permalink
ports/psoc6: First level changes to initiate make-pins script support.
Browse files Browse the repository at this point in the history
Signed-off-by: NikhitaR-IFX <Nikhita.Rajasekhar@infineon.com>
  • Loading branch information
NikhitaR-IFX committed Aug 28, 2023
1 parent 6aa2436 commit 9c4aef0
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ports/psoc6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ $(MPY_MAIN_BUILD_DIR)/firmware.elf: $(OBJ) $(MPY_MTB_LIBRARIES) $(LIBS)
$(MPY_MAIN_BUILD_DIR)/firmware.hex: $(MPY_MAIN_BUILD_DIR)/firmware.elf
$(Q) $(OBJCOPY) -O ihex $^ $@

MAKE_PINS = boards/make-pins.py
BOARD_PINS = $(BOARD_DIR)/pins.csv
PREFIX_FILE = boards/ra_pin_prefix.c

# include adapter makefile
include mtb-libs/makefile_mtb.mk
Expand Down
3 changes: 3 additions & 0 deletions ports/psoc6/boards/cy8c62xa_af.csv
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
151 changes: 151 additions & 0 deletions ports/psoc6/boards/make_pins.py
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

Check failure on line 12 in ports/psoc6/boards/make_pins.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

ports/psoc6/boards/make_pins.py:12:25: F821 Undefined name `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])

Check failure on line 62 in ports/psoc6/boards/make_pins.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

ports/psoc6/boards/make_pins.py:62:43: F821 Undefined name `parse_port_pin`
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))

Check failure on line 71 in ports/psoc6/boards/make_pins.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

ports/psoc6/boards/make_pins.py:71:38: F821 Undefined name `NamedPin`


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))

Check failure on line 86 in ports/psoc6/boards/make_pins.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F821)

ports/psoc6/boards/make_pins.py:86:44: F821 Undefined name `NamedPin`

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()


1 change: 1 addition & 0 deletions ports/psoc6/boards/pins.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
P0_0, P0_0
15 changes: 15 additions & 0 deletions ports/psoc6/boards/psoc6_prefix.c
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, \
}
11 changes: 10 additions & 1 deletion ports/psoc6/modules/machine/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,19 @@

// Add all machine pin objects - GPIO , I2C, ADC etc.
typedef struct _machine_pin_obj_t {
mp_obj_base_t base;
qstr name;
uint32_t pin;
uint8_t num_af;
//const pin_af_obj_t *af;
//const pin_ad_obj_t *ad;
} machine_pin_obj_t;

/*typedef struct _machine_pin_obj_t {
mp_obj_base_t base;
uint32_t pin_addr;
char *pin_name;
} machine_pin_obj_t;
} machine_pin_obj_t;*/

// Function Prototypes to support interaction between c<->py
int pin_find(mp_obj_t obj);
Expand Down

0 comments on commit 9c4aef0

Please sign in to comment.