Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
NanoSoC Testboard SDK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SoCLabs
NanoSoC Testboard SDK
Commits
404ad99e
Commit
404ad99e
authored
10 months ago
by
dwn1c21
Browse files
Options
Downloads
Patches
Plain Diff
Add FT1248 micropython demo
parent
dcb43a96
No related branches found
No related tags found
No related merge requests found
Pipeline
#11582
passed
10 months ago
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
nanosoc_board/micropython/nanosoc_demo1.py
+193
-0
193 additions, 0 deletions
nanosoc_board/micropython/nanosoc_demo1.py
with
193 additions
and
0 deletions
nanosoc_board/micropython/nanosoc_demo1.py
0 → 100644
+
193
−
0
View file @
404ad99e
from
machine
import
Pin
,
I2C
import
machine
from
micropython
import
const
import
time
import
rp2
from
rp2
import
PIO
# ----------- #
# ft1248x1_sm #
# ----------- #
ft1248x1_sm_SSN_PIN
=
24
ft1248x1_sm_SCLK_PIN
=
25
ft1248x1_sm_MIOSIO_PIN
=
22
ft1248x1_sm_MISO_PIN
=
23
@rp2.asm_pio
(
sideset_init
=
(
rp2
.
PIO
.
OUT_LOW
,
rp2
.
PIO
.
OUT_LOW
),
in_shiftdir
=
PIO
.
SHIFT_RIGHT
,
out_shiftdir
=
PIO
.
SHIFT_RIGHT
,
autopush
=
False
,
autopull
=
False
,
push_thresh
=
32
,
pull_thresh
=
32
,
fifo_join
=
PIO
.
JOIN_NONE
)
def
ft1248x1_sm
():
wrap_target
()
set
(
pindirs
,
3
)
.
side
(
3
)
# 0
label
(
"
1
"
)
mov
(
y
,
status
)
.
side
(
2
)
# 1
jmp
(
not_y
,
"
5
"
)
# 2
jmp
(
pin
,
"
1
"
)
# 3
jmp
(
"
6
"
)
# 4
label
(
"
5
"
)
wait
(
0
,
pin
,
2
)
.
side
(
0
)
# 5
label
(
"
6
"
)
set
(
pindirs
,
2
)
.
side
(
0
)
# 6
set
(
y
,
6
)
# 7
label
(
"
8
"
)
wait
(
1
,
pin
,
3
)
# 8
wait
(
0
,
pin
,
3
)
# 9
in_
(
pins
,
1
)
# 10
jmp
(
y_dec
,
"
8
"
)
# 11
mov
(
osr
,
reverse
(
isr
))
# 12
out
(
x
,
1
)
# 13
wait
(
1
,
pin
,
3
)
# 14
jmp
(
not_x
,
"
20
"
)
# 15
pull
(
noblock
)
# 16
mov
(
isr
,
null
)
# 17
set
(
pindirs
,
3
)
.
side
(
0
)
# 18
jmp
(
"
21
"
)
# 19
label
(
"
20
"
)
mov
(
osr
,
null
)
# 20
label
(
"
21
"
)
wait
(
0
,
pin
,
3
)
# 21
set
(
y
,
7
)
# 22
label
(
"
23
"
)
out
(
pins
,
1
)
# 23
wait
(
1
,
pin
,
3
)
# 24
wait
(
0
,
pin
,
3
)
# 25
in_
(
pins
,
1
)
# 26
jmp
(
y_dec
,
"
23
"
)
# 27
set
(
pindirs
,
3
)
.
side
(
3
)
# 28
jmp
(
x_dec
,
"
31
"
)
# 29
push
(
block
)
# 30
label
(
"
31
"
)
wait
(
1
,
pin
,
2
)
# 31
wrap
()
## @rp2.asm_pio(
# in_base = ft1248x1_sm_MIOSIO_PIN,
# in_shiftdir = PIO.SHIFT_LEFT,
# autopush=True, push_thresh=16,
# out_base = ft1248x1_sm_MIOSIO_PIN,
# set_base = ft1248x1_sm_MIOSIO_PIN,
# jmp_pin = ft1248x1_sm_SSN_PIN,
# out_shiftdir=0,
# autopull=False, pull_thresh=8,
# sideset_base = ft1248x1_sm_MIOSIO_PIN,
# sideset_init=(rp2.PIO.OUT_LOW, rp2.PIO.OUT_HIGH), out_init=rp2.PIO.OUT_LOW)
#sm0 = rp2.StateMachine(0, ft1248x1_sm, freq=125000,set_base=Pin(ft1248x1_sm_MIOSIO_PIN))
class
PIOSFT1248
:
def
__init__
(
self
):
Pin
(
ft1248x1_sm_SCLK_PIN
,
Pin
.
IN
)
Pin
(
ft1248x1_sm_SSN_PIN
,
Pin
.
IN
)
Pin
(
ft1248x1_sm_MISO_PIN
,
Pin
.
OUT
)
machine
.
mem32
[
0x502000CC
]
=
0x1801F000
machine
.
mem32
[
0x502000D0
]
=
0x3FFC0000
machine
.
mem32
[
0x502000DC
]
=
0x681B5AD6
pio
=
rp2
.
PIO
(
0
)
pio
.
state_machine
(
0
)
pio
.
add_program
(
ft1248x1_sm
)
machine
.
mem32
[
0x502000CC
]
=
0x1801F000
machine
.
mem32
[
0x502000D0
]
=
0x3FFC0000
machine
.
mem32
[
0x502000DC
]
=
0x681B5AD6
machine
.
mem32
[
0x50200000
]
=
0x1
def
write_blocking
(
self
,
wdata
):
for
b
in
wdata
:
while
((
machine
.
mem8
[
0x50200004
])
&
0x10000
!=
0
):
pass
machine
.
mem8
[
0x50200010
]
=
ord
(
b
)
def
read_blocking
(
self
,
n
):
data
=
""
for
i
in
range
(
n
):
while
((
machine
.
mem8
[
0x5020000C
])
&
const
(
0xF0
)
==
0
):
pass
data
+=
chr
((
machine
.
mem8
[
0x50200023
]))
return
data
def
enter_adp_mode
(
self
):
while
((
machine
.
mem8
[
0x50200004
])
&
0x10000
!=
0
):
pass
machine
.
mem8
[
0x50200010
]
=
0x1b
def
download_file
(
self
,
file
,
addr
):
pass
# def write_read_blocking(self,wdata):
# rdata = []
# for b in wdata:
# self._sm.put(b)
# rdata.append(self._sm.get() & 0xff)
# return rdata
#MCP23009 GPIO expander device controls reset and clock generator
MCP23009_ADDR
=
0x20
IODIR_ADDR
=
0
IPOL_ADDR
=
1
GPINTEN_ADDR
=
2
DEFVAL_ADDR
=
3
INTCON_ADDR
=
4
IOCON_ADDR
=
5
GPPU_ADDR
=
6
INTF_ADDR
=
7
INTCAP_ADDR
=
8
GPIO_ADDR
=
9
OLAT_ADDR
=
10
class
I2C_device_bus
:
def
__init__
(
self
):
self
.
i2c
=
I2C
(
1
,
scl
=
Pin
(
11
,
pull
=
Pin
.
PULL_UP
),
sda
=
Pin
(
10
,
pull
=
Pin
.
PULL_UP
))
def
scan
(
self
):
self
.
devices
=
self
.
i2c
.
scan
()
return
self
.
devices
class
MCP23009
:
def
init_MCP23009
(
self
,
I2C
):
I2C
.
writeto_mem
(
MCP23009_ADDR
,
IODIR_ADDR
,
b
'
\x00
'
)
I2C
.
writeto_mem
(
MCP23009_ADDR
,
OLAT_ADDR
,
b
'
\x1F
'
)
I2C
.
writeto_mem
(
MCP23009_ADDR
,
GPPU_ADDR
,
b
'
\x1F
'
)
time
.
sleep_ms
(
10
)
I2C
.
writeto_mem
(
MCP23009_ADDR
,
GPPU_ADDR
,
b
'
\x3F
'
)
I2C
.
writeto_mem
(
MCP23009_ADDR
,
OLAT_ADDR
,
b
'
\x3F
'
)
class
nanosoc_system
:
def
__init__
(
self
):
self
.
I2C
=
I2C_device_bus
()
self
.
MCP
=
MCP23009
()
def
init_nanosoc
(
self
):
self
.
MCP
.
init_MCP23009
(
self
.
I2C
.
i2c
)
print
(
"
Starting
"
)
machine
.
freq
(
125000000
)
FT1248
=
PIOSFT1248
()
nanosoc
=
nanosoc_system
()
devices
=
nanosoc
.
I2C
.
scan
()
if
len
(
devices
)
==
0
:
print
(
"
No i2c device!
"
)
else
:
print
(
"
I2C devices found:
"
,
len
(
devices
))
for
device
in
devices
:
print
(
"
I2C hexadecimal address:
"
,
hex
(
device
))
nanosoc
.
init_nanosoc
()
while
((
machine
.
mem32
[
0x50200004
])
&
const
(
0x100
)
==
0
):
data
=
FT1248
.
read_blocking
(
2
)
print
((
data
),
end
=
''
)
print
(
"
Enter ADP
"
)
FT1248
.
enter_adp_mode
()
while
((
machine
.
mem32
[
0x50200004
])
&
const
(
0x100
)
==
0
):
data
=
FT1248
.
read_blocking
(
2
)
print
((
data
),
end
=
''
)
print
(
"
Write address
"
)
FT1248
.
write_blocking
(
"
A 0x20000000
\n
"
)
time
.
sleep_ms
(
10
)
while
True
:
if
((
machine
.
mem32
[
0x5020000C
])
&
const
(
0xF0
)
!=
0
):
data
=
FT1248
.
read_blocking
(
10
)
#s = ''.join(chr(x) for x in data)
print
((
data
),
end
=
''
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment