Skip to content

Commit 36821d0

Browse files
author
Daniel Campora
committed
cc3200: Add alternate functions list to Pin object.
Also remove pin.high() and pin.low() methods.
1 parent d5e2564 commit 36821d0

13 files changed

Lines changed: 167 additions & 146 deletions

File tree

cc3200/application.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ APP_HAL_SRC_C = $(addprefix hal/,\
7777
APP_MISC_SRC_C = $(addprefix misc/,\
7878
antenna.c \
7979
FreeRTOSHooks.c \
80-
pin_named_pins.c \
8180
help.c \
8281
mpcallback.c \
8382
mperror.c \

cc3200/boards/cc3200_af.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Pin,Name,Default,AF0,AF1,AF2,AF3,AF4,AF5,AF6,AF7,AF8,AF9,AF10,AF11,AF12,AF13,AF1
5353
52,RTC_XTAL_N,RTC_XTAL_N,GP32,,I2S0_CLK,,I2S0_DAT0,,UART0_RTS,,SPI0_MOSI,,,,,,,,
5454
53,GP30,GP30,GP30,,I2S0_CLK,I2S0_FS,TIM2_CC1,,,SPI0_MISO,,UART0_TX,,,,,,,
5555
54,VIN_IO2,VIN_IO2,VIN_IO2,,,,,,,,,,,,,,,,
56-
55,GP1,GP1,GP1,,,SPI0_MISO,pCLK (PIXCLK),,UART1_TX,TIM0_CC1,,,,,,,,,
56+
55,GP1,GP1,GP1,,,UART0_TX,pCLK (PIXCLK),,UART1_TX,TIM0_CC1,,,,,,,,,
5757
56,VDD_DIG2,VDD_DIG2,VDD_DIG2,,,,,,,,,,,,,,,,
5858
57,GP2,GP2,GP2,,,UART0_RX,,,UART1_RX,TIM1_CC0,,,,,,,,,ADC0_CH0
5959
58,GP3,GP3,GP3,,,,pDATA7(CAM_D3),,UART1_TX,,,,,,,,,,ADC0_CH1

cc3200/boards/cc3200_prefix.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,29 @@
3939
#include "pybpin.h"
4040

4141

42-
#define PIN(p_pin_name, p_port, p_bit, p_pin_num) \
42+
#define AF(af_name, af_idx, af_fn, af_unit, af_type) \
43+
{ \
44+
.name = MP_QSTR_ ## af_name, \
45+
.idx = (af_idx), \
46+
.fn = PIN_FN_ ## af_fn, \
47+
.unit = (af_unit), \
48+
.type = PIN_TYPE_ ## af_fn ## _ ## af_type, \
49+
}
50+
51+
52+
#define PIN(p_pin_name, p_port, p_bit, p_pin_num, p_af_list, p_num_afs) \
4353
{ \
4454
{ &pin_type }, \
4555
.name = MP_QSTR_ ## p_pin_name, \
4656
.port = PORT_A ## p_port, \
57+
.af_list = (p_af_list), \
4758
.pull = PIN_TYPE_STD, \
4859
.bit = (p_bit), \
4960
.pin_num = (p_pin_num), \
5061
.af = PIN_MODE_0, \
5162
.strength = PIN_STRENGTH_4MA, \
5263
.mode = GPIO_DIR_MODE_IN, \
64+
.num_afs = (p_num_afs), \
5365
.value = 0, \
54-
.isused = false, \
66+
.used = false, \
5567
}

cc3200/boards/make-pins.py

Lines changed: 74 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
"""Generates the pins files for the CC3200."""
2+
"""Generates the pins file for the CC3200."""
33

44
from __future__ import print_function
55

@@ -8,6 +8,15 @@
88
import csv
99

1010

11+
SUPPORTED_AFS = { 'UART': ('TX', 'RX', 'RTS', 'CTS'),
12+
'SPI': ('CLK', 'MOSI', 'MISO', 'CS0'),
13+
#'I2S': ('CLK', 'FS', 'DAT0', 'DAT1'),
14+
'I2C': ('SDA', 'SCL'),
15+
'TIM': ('PWM0', 'PWM1', 'CC0', 'CC1'),
16+
'SD': ('CLK', 'CMD', 'DAT0'),
17+
'ADC': ('CH0', 'CH1', 'CH2', 'CH3')
18+
}
19+
1120
def parse_port_pin(name_str):
1221
"""Parses a string and returns a (port, gpio_bit) tuple."""
1322
if len(name_str) < 3:
@@ -21,53 +30,64 @@ def parse_port_pin(name_str):
2130
return (port, gpio_bit)
2231

2332

24-
class Pin(object):
33+
class AF:
34+
"""Holds the description of an alternate function"""
35+
def __init__(self, name, idx, fn, unit, type):
36+
self.name = name
37+
self.idx = idx
38+
self.fn = fn
39+
self.unit = unit
40+
self.type = type
41+
42+
def print(self):
43+
print (' AF({:16s}, {:4d}, {:8s}, {:4d}, {:8s}), // {}'.format(self.name, self.idx, self.fn, self.unit, self.type, self.name))
44+
45+
class Pin:
2546
"""Holds the information associated with a pin."""
2647
def __init__(self, name, port, gpio_bit, pin_num):
2748
self.name = name
2849
self.port = port
2950
self.gpio_bit = gpio_bit
3051
self.pin_num = pin_num
3152
self.board_pin = False
53+
self.afs = []
3254

33-
def cpu_pin_name(self):
34-
return self.name
35-
36-
def is_board_pin(self):
37-
return self.board_pin
38-
39-
def set_is_board_pin(self):
40-
self.board_pin = True
55+
def add_af(self, af):
56+
self.afs.append(af)
4157

4258
def print(self):
43-
print('pin_obj_t pin_{:6s} = PIN({:6s}, {:1d}, {:3d}, {:2d});'.format(
44-
self.name, self.name, self.port, self.gpio_bit, self.pin_num))
59+
print('// {}'.format(self.name))
60+
print('const pin_af_t pin_{}_af[] = {{'.format(self.name))
61+
for af in self.afs:
62+
af.print()
63+
print('};')
64+
print('pin_obj_t pin_{:4s} = PIN({:6s}, {:1d}, {:3d}, {:2d}, pin_{}_af, {});\n'.format(
65+
self.name, self.name, self.port, self.gpio_bit, self.pin_num, self.name, len(self.afs)))
4566

4667
def print_header(self, hdr_file):
4768
hdr_file.write('extern pin_obj_t pin_{:s};\n'.format(self.name))
4869

4970

50-
class Pins(object):
51-
71+
class Pins:
5272
def __init__(self):
53-
self.cpu_pins = [] # list of pin objects
73+
self.board_pins = [] # list of pin objects
5474

5575
def find_pin(self, port, gpio_bit):
56-
for pin in self.cpu_pins:
76+
for pin in self.board_pins:
5777
if pin.port == port and pin.gpio_bit == gpio_bit:
5878
return pin
5979

6080
def find_pin_by_num(self, pin_num):
61-
for pin in self.cpu_pins:
81+
for pin in self.board_pins:
6282
if pin.pin_num == pin_num:
6383
return pin
6484

6585
def find_pin_by_name(self, name):
66-
for pin in self.cpu_pins:
86+
for pin in self.board_pins:
6787
if pin.name == name:
6888
return pin
6989

70-
def parse_af_file(self, filename, pin_col, pinname_col):
90+
def parse_af_file(self, filename, pin_col, pinname_col, af_start_col):
7191
with open(filename, 'r') as csvfile:
7292
rows = csv.reader(csvfile)
7393
for row in rows:
@@ -76,11 +96,21 @@ def parse_af_file(self, filename, pin_col, pinname_col):
7696
except:
7797
continue
7898
if not row[pin_col].isdigit():
79-
raise ValueError("Invalid pin number: {:s} in row {:s}".format(row[pin_col]), row)
99+
raise ValueError("Invalid pin number {:s} in row {:s}".format(row[pin_col]), row)
80100
# Pin numbers must start from 0 when used with the TI API
81101
pin_num = int(row[pin_col]) - 1;
82102
pin = Pin(row[pinname_col], port_num, gpio_bit, pin_num)
83-
self.cpu_pins.append(pin)
103+
self.board_pins.append(pin)
104+
af_idx = 0
105+
for af in row[af_start_col:]:
106+
af_splitted = af.split('_')
107+
fn_name = af_splitted[0].rstrip('0123456789')
108+
if fn_name in SUPPORTED_AFS:
109+
type_name = af_splitted[1]
110+
if type_name in SUPPORTED_AFS[fn_name]:
111+
unit_idx = af_splitted[0][-1]
112+
pin.add_af(AF(af, af_idx, fn_name, int(unit_idx), type_name))
113+
af_idx += 1
84114

85115
def parse_board_file(self, filename, cpu_pin_col):
86116
with open(filename, 'r') as csvfile:
@@ -92,37 +122,44 @@ def parse_board_file(self, filename, cpu_pin_col):
92122
else:
93123
pin = self.find_pin_by_name(row[cpu_pin_col])
94124
if pin:
95-
pin.set_is_board_pin()
125+
pin.board_pin = True
96126

97127
def print_named(self, label, pins):
98128
print('')
99129
print('STATIC const mp_map_elem_t pin_{:s}_pins_locals_dict_table[] = {{'.format(label))
100130
for pin in pins:
101-
if pin.is_board_pin():
102-
print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:6s}), (mp_obj_t)&pin_{:6s} }},'.format(pin.cpu_pin_name(), pin.cpu_pin_name()))
131+
if pin.board_pin:
132+
print(' {{ MP_OBJ_NEW_QSTR(MP_QSTR_{:6s}), (mp_obj_t)&pin_{:6s} }},'.format(pin.name, pin.name))
103133
print('};')
104134
print('MP_DEFINE_CONST_DICT(pin_{:s}_pins_locals_dict, pin_{:s}_pins_locals_dict_table);'.format(label, label));
105135

106136
def print(self):
107-
for pin in self.cpu_pins:
108-
if pin.is_board_pin():
137+
for pin in self.board_pins:
138+
if pin.board_pin:
109139
pin.print()
110-
self.print_named('board', self.cpu_pins)
140+
self.print_named('board', self.board_pins)
111141
print('')
112142

113143
def print_header(self, hdr_filename):
114144
with open(hdr_filename, 'wt') as hdr_file:
115-
for pin in self.cpu_pins:
116-
if pin.is_board_pin():
145+
for pin in self.board_pins:
146+
if pin.board_pin:
117147
pin.print_header(hdr_file)
118148

119149
def print_qstr(self, qstr_filename):
120150
with open(qstr_filename, 'wt') as qstr_file:
121-
qstr_set = set([])
122-
for pin in self.cpu_pins:
123-
if pin.is_board_pin():
124-
qstr_set |= set([pin.cpu_pin_name()])
125-
for qstr in sorted(qstr_set):
151+
pin_qstr_set = set([])
152+
af_qstr_set = set([])
153+
for pin in self.board_pins:
154+
if pin.board_pin:
155+
pin_qstr_set |= set([pin.name])
156+
for af in pin.afs:
157+
af_qstr_set |= set([af.name])
158+
print('// Board pins', file=qstr_file)
159+
for qstr in sorted(pin_qstr_set):
160+
print('Q({})'.format(qstr), file=qstr_file)
161+
print('\n// Pin AFs', file=qstr_file)
162+
for qstr in sorted(af_qstr_set):
126163
print('Q({})'.format(qstr), file=qstr_file)
127164

128165

@@ -169,12 +206,12 @@ def main():
169206
print('//')
170207
if args.af_filename:
171208
print('// --af {:s}'.format(args.af_filename))
172-
pins.parse_af_file(args.af_filename, 0, 1)
209+
pins.parse_af_file(args.af_filename, 0, 1, 3)
173210

174211
if args.board_filename:
175212
print('// --board {:s}'.format(args.board_filename))
176-
pins.parse_board_file(args.board_filename, 1)
177-
213+
pins.parse_board_file(args.board_filename, 1)
214+
178215
if args.prefix_filename:
179216
print('// --prefix {:s}'.format(args.prefix_filename))
180217
print('')

cc3200/misc/pin_named_pins.c

Lines changed: 0 additions & 71 deletions
This file was deleted.

cc3200/mods/pybpin.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,6 @@ STATIC const mp_map_elem_t pin_locals_dict_table[] = {
779779
// instance methods
780780
{ MP_OBJ_NEW_QSTR(MP_QSTR_init), (mp_obj_t)&pin_init_obj },
781781
{ MP_OBJ_NEW_QSTR(MP_QSTR_value), (mp_obj_t)&pin_value_obj },
782-
{ MP_OBJ_NEW_QSTR(MP_QSTR_low), (mp_obj_t)&pin_low_obj },
783-
{ MP_OBJ_NEW_QSTR(MP_QSTR_high), (mp_obj_t)&pin_high_obj },
784782
{ MP_OBJ_NEW_QSTR(MP_QSTR_toggle), (mp_obj_t)&pin_toggle_obj },
785783
{ MP_OBJ_NEW_QSTR(MP_QSTR_id), (mp_obj_t)&pin_id_obj },
786784
{ MP_OBJ_NEW_QSTR(MP_QSTR_mode), (mp_obj_t)&pin_mode_obj },

0 commit comments

Comments
 (0)