Skip to content

Commit

Permalink
update resource
Browse files Browse the repository at this point in the history
Signed-off-by: huangziyi <[email protected]>
  • Loading branch information
MrThanlon committed Mar 15, 2024
1 parent 2d442b2 commit a67428e
Show file tree
Hide file tree
Showing 46 changed files with 2,379 additions and 1,251 deletions.
1 change: 1 addition & 0 deletions share/qtcreator/examples/01-Media/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from media.display import *
from media.media import *
import time, os
import sys

def camera_test():
print("camera_test")
Expand Down
83 changes: 83 additions & 0 deletions share/qtcreator/examples/01-Media/camera_2sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Camera Example
#
# Note: You will need an SD card to run this example.
#
# You can start 2 camera preview.

from media.camera import *
from media.display import *
from media.media import *
import time, os
import sys

def camera_test():
print("camera_test")
# use hdmi for display
display.init(LT9611_1920X1080_30FPS)
camera.sensor_init(CAM_DEV_ID_0, CAM_DEFAULT_SENSOR)
out_width = 640
out_height = 480
# set camera out width align up with 16Bytes
out_width = ALIGN_UP(out_width, 16)
# set chn0 output size
camera.set_outsize(CAM_DEV_ID_0, CAM_CHN_ID_0, out_width, out_height)
# set chn0 out format
camera.set_outfmt(CAM_DEV_ID_0, CAM_CHN_ID_0, PIXEL_FORMAT_YUV_SEMIPLANAR_420)
# create meida source device
meida_source = media_device(CAMERA_MOD_ID, CAM_DEV_ID_0, CAM_CHN_ID_0)
# create meida sink device
meida_sink = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_VIDEO1)
# create meida link
media.create_link(meida_source, meida_sink)
# set display plane with video channel
display.set_plane(160, 160, out_width, out_height, PIXEL_FORMAT_YVU_PLANAR_420, DISPLAY_MIRROR_NONE, DISPLAY_CHN_VIDEO1)


camera.sensor_init(CAM_DEV_ID_1, CAM_OV5647_1920X1080_CSI1_30FPS_10BIT_USEMCLK_LINEAR)
out_width = 640
out_height = 480
# set camera out width align up with 16Bytes
out_width = ALIGN_UP(out_width, 16)
# set chn0 output size
camera.set_outsize(CAM_DEV_ID_1, CAM_CHN_ID_0, out_width, out_height)
# set chn0 out format
camera.set_outfmt(CAM_DEV_ID_1, CAM_CHN_ID_0, PIXEL_FORMAT_YUV_SEMIPLANAR_420)
# create meida source device
meida_source1 = media_device(CAMERA_MOD_ID, CAM_DEV_ID_1, CAM_CHN_ID_0)
# create meida sink device
meida_sink1 = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_VIDEO2)
# create meida link
media.create_link(meida_source1, meida_sink1)
# set display plane with video channel
display.set_plane(960, 480, out_width, out_height, PIXEL_FORMAT_YVU_PLANAR_420, DISPLAY_MIRROR_NONE, DISPLAY_CHN_VIDEO2)

# init meida buffer
media.buffer_init()
# start stream for camera device0
camera.start_mcm_stream()

try:
while True:
os.exitpoint()
time.sleep(5)
except KeyboardInterrupt as e:
print("user stop: ", e)
except BaseException as e:
sys.print_exception(e)
# stop stream for camera device0
camera.stop_mcm_stream()

# deinit display
display.deinit()
# destroy media link
media.destroy_link(meida_source, meida_sink)
media.destroy_link(meida_source1, meida_sink1)

os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
time.sleep_ms(100)
# deinit media buffer
media.buffer_deinit()

if __name__ == "__main__":
os.exitpoint(os.EXITPOINT_ENABLE)
camera_test()
103 changes: 103 additions & 0 deletions share/qtcreator/examples/01-Media/camera_3sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Camera Example
#
# Note: You will need an SD card to run this example.
#
# You can start 3 camera preview.

from media.camera import *
from media.display import *
from media.media import *
import time, os
import sys

def camera_test():
print("camera_test")
# use hdmi for display
display.init(LT9611_1920X1080_30FPS)
camera.sensor_init(CAM_DEV_ID_0, CAM_DEFAULT_SENSOR)
out_width = 640
out_height = 480
# set camera out width align up with 16Bytes
out_width = ALIGN_UP(out_width, 16)
# set chn0 output size
camera.set_outsize(CAM_DEV_ID_0, CAM_CHN_ID_0, out_width, out_height)
# set chn0 out format
camera.set_outfmt(CAM_DEV_ID_0, CAM_CHN_ID_0, PIXEL_FORMAT_YUV_SEMIPLANAR_420)
# create meida source device
meida_source = media_device(CAMERA_MOD_ID, CAM_DEV_ID_0, CAM_CHN_ID_0)
# create meida sink device
meida_sink = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_VIDEO1)
# create meida link
media.create_link(meida_source, meida_sink)
# set display plane with video channel
display.set_plane(0, 0, out_width, out_height, PIXEL_FORMAT_YVU_PLANAR_420, DISPLAY_MIRROR_NONE, DISPLAY_CHN_VIDEO1)


camera.sensor_init(CAM_DEV_ID_1, CAM_OV5647_1920X1080_CSI1_30FPS_10BIT_USEMCLK_LINEAR)
out_width = 640
out_height = 480
# set camera out width align up with 16Bytes
out_width = ALIGN_UP(out_width, 16)
# set chn0 output size
camera.set_outsize(CAM_DEV_ID_1, CAM_CHN_ID_0, out_width, out_height)
# set chn0 out format
camera.set_outfmt(CAM_DEV_ID_1, CAM_CHN_ID_0, PIXEL_FORMAT_YUV_SEMIPLANAR_420)
# create meida source device
meida_source1 = media_device(CAMERA_MOD_ID, CAM_DEV_ID_1, CAM_CHN_ID_0)
# create meida sink device
meida_sink1 = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_VIDEO2)
# create meida link
media.create_link(meida_source1, meida_sink1)
# set display plane with video channel
display.set_plane(640, 320, out_width, out_height, PIXEL_FORMAT_YVU_PLANAR_420, DISPLAY_MIRROR_NONE, DISPLAY_CHN_VIDEO2)


camera.sensor_init(CAM_DEV_ID_2, CAM_OV5647_1920X1080_CSI2_30FPS_10BIT_USEMCLK_LINEAR)
out_width = 640
out_height = 480
# set camera out width align up with 16Bytes
out_width = ALIGN_UP(out_width, 16)
# set chn0 output size
camera.set_outsize(CAM_DEV_ID_2, CAM_CHN_ID_0, out_width, out_height)
# set chn0 out format
camera.set_outfmt(CAM_DEV_ID_2, CAM_CHN_ID_0, PIXEL_FORMAT_RGB_888)
# create meida source device
meida_source2 = media_device(CAMERA_MOD_ID, CAM_DEV_ID_2, CAM_CHN_ID_0)
# create meida sink device
meida_sink2 = media_device(DISPLAY_MOD_ID, DISPLAY_DEV_ID, DISPLAY_CHN_OSD0)
# create meida link1
media.create_link(meida_source2, meida_sink2)
# set display plane with video channel
display.set_plane(1280, 600, out_width, out_height, PIXEL_FORMAT_RGB_888, DISPLAY_MIRROR_NONE, DISPLAY_CHN_OSD0)


# init meida buffer
media.buffer_init()
# start stream for camera device0
camera.start_mcm_stream()

try:
while True:
os.exitpoint()
time.sleep(5)
except KeyboardInterrupt as e:
print("user stop: ", e)
except BaseException as e:
sys.print_exception(e)
# stop stream for camera device0
camera.stop_mcm_stream()

# deinit display
display.deinit()
# destroy media link
media.destroy_link(meida_source, meida_sink)
media.destroy_link(meida_source1, meida_sink1)
media.destroy_link(meida_source2, meida_sink2)
os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
time.sleep_ms(100)
# deinit media buffer
media.buffer_deinit()

if __name__ == "__main__":
os.exitpoint(os.EXITPOINT_ENABLE)
camera_test()
14 changes: 6 additions & 8 deletions share/qtcreator/examples/02-Machine/adc/adc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# 基础示例
#
# 欢迎使用CanMV IDE, 点击IDE左下角的绿色按钮开始执行脚本

from machine import ADC

adc = ADC(0,enable=True) #构造adc对象,通道0默认开启
value = adc.value() #获取通道0的数值
print("value = %d" % value)
adc.deinit() #注销adc对象
# 实例化ADC通道0
adc = ADC(0)
# 获取ADC通道0采样值
print(adc.read_u16())
# 获取ADC通道0电压值
print(adc.read_uv(), "uV")
41 changes: 16 additions & 25 deletions share/qtcreator/examples/02-Machine/fpioa/fpioa.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
from machine import FPIOA
a = FPIOA()


a.help()
for i in range(63):
a.help(i)

for i in range(221):
a.get_Pin_num(i)

a.help(60)
a.set_function(60,a.GPIO60)
a.help(60)

a.set_function(60,set_sl=1,set_ie=0,set_oe=0,set_pd=1,set_pu=0,set_ds=6,set_st=0,set_di=1)
a.help(60)
try :
print(a.set_function(60,set_msc=0))

except Exception as e:
print("set error ", e)

a.help(60)



# 实例化FPIOA
fpioa = FPIOA()
# 打印所有引脚配置
fpioa.help()
# 打印指定引脚详细配置
fpioa.help(0)
# 打印指定功能所有可用的配置引脚
fpioa.help(FPIOA.IIC0_SDA, func=True)
# 设置Pin0为GPIO0
fpioa.set_function(0, FPIOA.GPIO0)
# 设置Pin2为GPIO2, 同时配置其它项
fpioa.set_function(2, FPIOA.GPIO2, ie=1, oe=1, pu=0, pd=0, st=1, sl=0, ds=7)
# 获取指定功能当前所在的引脚
fpioa.get_pin_num(FPIOA.UART0_TXD)
# 获取指定引脚当前功能
fpioa.get_pin_func(0)
6 changes: 6 additions & 0 deletions share/qtcreator/examples/02-Machine/gpio/gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# 欢迎使用CanMV IDE, 点击IDE左下角的绿色按钮开始执行脚本

from machine import GPIO
from machine import FPIOA

a = FPIOA()
a.help(8)
a.set_function(8,a.GPIO8)
a.help(8)

gpio = GPIO(8, GPIO.OUT, GPIO.PULL_UP, value=0) #构造GPIO对象,gpio编号为8,设置为上拉输出低电平
value = gpio.value() #获取gpio的值
Expand Down
34 changes: 34 additions & 0 deletions share/qtcreator/examples/02-Machine/pin/pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from machine import Pin
from machine import FPIOA

# 实例化FPIOA
fpioa = FPIOA()
# 设置Pin2为GPIO2
fpioa.set_function(2, FPIOA.GPIO2)

# 实例化Pin2为输出
pin = Pin(2, Pin.OUT, pull=Pin.PULL_NONE, drive=7)
# 设置输出为高
pin.value(1)
# pin.on()
# pin.high()
# 设置输出为低
pin.value(0)
# pin.off()
# pin.low()
# 初始化Pin2为输入
pin.init(Pin.IN, pull=Pin.PULL_UP, drive=7)
# 获取输入
print(pin.value())
# 设置模式
pin.mode(Pin.IN)
# 获取模式
print(pin.mode())
# 设置上下拉
pin.pull(Pin.PULL_NONE)
# 获取上下拉
print(pin.pull())
# 设置驱动能力
pin.drive(7)
# 获取驱动能力
print(pin.drive())
6 changes: 6 additions & 0 deletions share/qtcreator/examples/02-Machine/pwm/pwm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from machine import PWM
from machine import FPIOA

# 实例化FPIOA
fpioa = FPIOA()
# 设置PIN60为PWM通道0
fpioa.set_function(60, fpioa.PWM0)
# 实例化PWM通道0,频率为1000Hz,占空比为50%,默认使能输出
pwm0 = PWM(0, 1000, 50, enable = True)
# 关闭通道0输出
Expand Down
8 changes: 8 additions & 0 deletions share/qtcreator/examples/02-Machine/rtc/rtc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from machine import RTC

# 实例化RTC
rtc = RTC()
# 获取当前时间
print(rtc.datetime())
# 设置当前时间
rtc.init((2024,2,28,2,23,59,0,0))
19 changes: 11 additions & 8 deletions share/qtcreator/examples/02-Machine/timer/timer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# 基础示例
#
# 欢迎使用CanMV IDE, 点击IDE左下角的绿色按钮开始执行脚本

from machine import Timer
def on_timer(arg): #定义定时器回调函数
print("time up: %d" % arg)

tim = Timer(mode=Timer.MODE_ONE_SHOT,period=3, unit=Timer.UNIT_S, callback=on_timer, arg=1, start=True) #构造定时器对象,时间为3s,默认开启定时器
import time

# 实例化一个软定时器
tim = Timer(-1)
# 初始化定时器为单次模式,周期100ms
tim.init(period=100, mode=Timer.ONE_SHOT, callback=lambda t:print(1))
time.sleep(0.2)
# 初始化定时器为周期模式,频率为1Hz
tim.init(freq=1, mode=Timer.PERIODIC, callback=lambda t:print(2))
time.sleep(2)
# 释放定时器资源
tim.deinit()
9 changes: 8 additions & 1 deletion share/qtcreator/examples/02-Machine/uart/uart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from machine import UART
# UART1: baudrate 115200, 8bits, parity none, one stopbits
from machine import FPIOA

# 实例化FPIOA
fpioa = FPIOA()
# 设置PIN60为PWM通道0
fpioa.set_function(5, fpioa.UART2_TXD)
fpioa.set_function(6, fpioa.UART2_RXD)
# UART2: baudrate 115200, 8bits, parity none, one stopbits
uart = UART(UART.UART2, baudrate=115200, bits=UART.EIGHTBITS, parity=UART.PARITY_NONE, stop=UART.STOPBITS_ONE)
# UART write
r = uart.write("UART test")
Expand Down
Loading

0 comments on commit a67428e

Please sign in to comment.