Example #1
0
class Fpioa_Manager:
    def __init__(self):
        self.board_dict = {}
        self.fpioa_dict = {}
        self.fpioa = FPIOA()
        self.board_info = board_info

    def register(self, pin=None, function=None, force=True):
        if pin == None or function == None:
            print("Please enter Pin and function")
            return -1
        find_pin, find_func = self.find_dict(pin, function)
        if (find_pin == None and find_func == None) or force:
            self.board_dict[pin] = function
            self.fpioa_dict[function] = pin
            self.fpioa.set_function(pin, function)
            return 1
        else:
            return find_pin, find_func

    def unregister(self, pin=None, function=None):
        if pin == None and function == None:
            print("Please enter Pin and function")
            return -1
        find_pin, find_func = self.find_dict(pin, function)
        if find_pin != None or find_func != None:
            ret_func = self.board_dict.pop(find_pin)
            ret_pin = self.fpioa_dict.pop(find_func)
            return ret_pin, ret_func
        else:
            print("This function and pin have not been registered yet")
            return 0

    def find_dict(self, pin, function):
        bd_pin, bd_func = self.__find_board_dict(pin)
        fp_pin, fp_func = self.__find_fpioa_dict(function)
        if bd_pin != None or bd_func != None:
            return bd_pin, bd_func
        elif fp_pin != None or fp_func != None:
            return fp_pin, fp_func
        else:
            return None, None

    def __find_board_dict(self, pin):
        if pin == None:
            return None, None
        function = self.board_dict.get(pin)
        if function == None:
            return None, None
        else:
            return pin, self.board_dict[pin]

    def __find_fpioa_dict(self, function):
        if function == None:
            return None, None
        pin = self.fpioa_dict.get(function)
        if pin == None:
            return None, None
        else:
            return self.fpioa_dict[function], function
Example #2
0
class Fpioa_Manager:
    def __init__(self):
        self.board_dict={}
        self.fpioa_dict={}
        self.fpioa = FPIOA()
        self.board_info = board_info
    def register(self,pin = None,function = None):
        if pin == None or function == None:
            print("Please enter Pin and function")
            return -1
        find_pin,find_func = self.find_dict(pin,function)
        if find_pin == None and find_func == None:
            self.board_dict[pin] = function
            self.fpioa_dict[function] = pin
            self.fpioa.set_function(pin,function)
            return 1
        else:
            return find_pin,find_func
    def unregister(self,pin = None,function = None):
        if pin == None and function == None:
            print("Please enter Pin and function")
            return -1
        find_pin,find_func = self.find_dict(pin,function)
        if find_pin != None or find_func != None:
            ret_func=self.board_dict.pop(find_pin)
            ret_pin=self.fpioa_dict.pop(find_func)
            return ret_pin,ret_func
        else:
            print("This function and pin have not been registered yet")
            return 0
    def find_dict(self,pin,function):
        bd_pin,bd_func = self.__find_board_dict(pin)
        fp_pin,fp_func = self.__find_fpioa_dict(function)
        if bd_pin != None or bd_func != None:
            return bd_pin,bd_func
        elif fp_pin != None or fp_func != None:
            return fp_pin,fp_func
        else:
            return None,None
    def __find_board_dict(self,pin):
        if pin == None:
            return None,None
        function = self.board_dict.get(pin)
        if function == None:
            return None,None
        else :
            return pin,self.board_dict[pin]
    def __find_fpioa_dict(self,function):
        if function == None:
            return None,None
        pin = self.fpioa_dict.get(function)
        if pin == None:
            return None,None
        else:
            return self.fpioa_dict[function],function
class fm:
  fpioa = FPIOA()

  def help():
    __class__.fpioa.help()

  def get_pin_by_function(function):
    return __class__.fpioa.get_Pin_num(function)

  def register(pin, function, force=False):
    pin_used = __class__.get_pin_by_function(function)
    if pin_used == pin:
      return 
    if None != pin_used:
      info = "[Warning] function is used by %s(pin:%d)" % (
          fm.str_function(function), pin_used)
      if force == False:
        raise Exception(info)
      else:
        print(info)
    __class__.fpioa.set_function(pin, function)

  def unregister(pin):
    __class__.fpioa.set_function(pin, fm.fpioa.RESV0)

  def str_function(function):
    if fm.fpioa.GPIOHS0 <= function and function <= fm.fpioa.GPIO7:
      if fm.fpioa.GPIO0 <= function:
        return 'fm.fpioa.GPIO%d' % (function - fm.fpioa.GPIO0)
      return 'fm.fpioa.GPIOHS%d' % (function - fm.fpioa.GPIOHS0)
    return 'unknown'

  def get_gpio_used():
    return [(__class__.str_function(f), __class__.get_pin_by_function(f)) for f in range(fm.fpioa.GPIOHS0, fm.fpioa.GPIO7 + 1)]
Example #4
0
from fpioa_manager import *
import os, Maix, lcd, image
from Maix import FPIOA, GPIO

fpioa = FPIOA()

in_pin = 22  # Actual pin on the Maix
fpioa.set_function(in_pin,
                   FPIOA.GPIO6)  # How the k210 gpio6 gets routed to pin 22
in_gpio = GPIO(GPIO.GPIO6, GPIO.IN)  # How the k210 knows what GPIO6 should do

lcd.init(color=lcd.WHITE)
lcd.draw_string(0, 0, "Testing pin 22 as GPIO6", lcd.BLACK, lcd.WHITE)

while True:
    lcd.draw_string(0, 50, "pin 22 value is: %d" % in_gpio.value(), lcd.BLACK,
                    lcd.WHITE)
Example #5
0
import sensor, image, lcd, utime  # import 相关库
from fpioa_manager import *
import KPU as kpu
import time, uos
from Maix import FPIOA, GPIO
from fpioa_manager import fm, board_info
from Maix import GPIO
from machine import UART
task_fd = kpu.load(0x200000)  # 从flash 0x200000 加载人脸检测模型
task_ld = kpu.load(0x300000)  # 从flash 0x300000 加载人脸五点关键点检测模型
task_fe = kpu.load(0x400000)  # 从flash 0x400000 加载人脸196维特征值模型
clock = time.clock()  # 初始化系统时钟,计算帧率
key_pin = 16  # 设置按键引脚 FPIO16
fpioa = FPIOA()
fpioa.set_function(key_pin, FPIOA.GPIO7)
key_gpio = GPIO(GPIO.GPIO7, GPIO.IN)
last_key_state = 1
key_pressed = 0  # 初始化按键引脚 分配GPIO7 到 FPIO16


def check_key():  # 按键检测函数,用于在循环中检测按键是否按下,下降沿有效
    global last_key_state
    global key_pressed
    val = key_gpio.value()
    if last_key_state == 1 and val == 0:
        key_pressed = 1
    else:
        key_pressed = 0
    last_key_state = val

Example #6
0
 def __init__(self):
     self.board_dict={}
     self.fpioa_dict={}
     self.fpioa = FPIOA()
     self.board_info = board_info
Example #7
0
 def __init__(self):
     self.board_dict={}
     self.fpioa_dict={}
     self.fpioa = FPIOA()
     self.board_info = board_info
Example #8
0
from fpioa_manager import *
import os, Maix, lcd, image
from Maix import FPIOA, GPIO

test_pin = 16
fpioa = FPIOA()
fpioa.set_function(test_pin, FPIOA.GPIO7)
test_gpio = GPIO(GPIO.GPIO7, GPIO.IN)
lcd.init(color=(255, 0, 0))
lcd.draw_string(100, 120, "Welcome to MaixPy", lcd.WHITE, lcd.RED)
if test_gpio.value() == 0:
    print('PIN 16 pulled down, enter test mode')
    import sensor
    import image
    sensor.reset()
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.run(1)
    lcd.freq(16000000)
    while False:  #True:
        img = sensor.snapshot()
        lcd.display(img)
Example #9
0
    except:
        img = image.Image()

    image.font_free()

    a = img.draw_string(5, 5, s, scale=1, color=(255,0,0), x_spacing=1, mono_space=0)
    lcd.display(img)
    del(img)

    time.sleep(2)

try:
    first_boot = "first_boot" in os.listdir("/flash")

    boot_pressed = 0
    fpioa = FPIOA()
    fpioa.set_function(16, FPIOA.GPIO7)
    test_gpio = GPIO(GPIO.GPIO7, GPIO.IN, GPIO.PULL_UP)

    lcd.init()
    lcd.rotation(1)

    if first_boot:
        draw_on_image('/flash/logo.jpg', interface_strings[lang]['First boot'], 70, 220, size = 2, space = 0)
        os.remove("/flash/first_boot")
        time.sleep(2)
        gc.collect()
        from preloaded import *

    else:
        lcd.display(image.Image('logo.jpg'))
Example #10
0
    elif (event == 'out'):
        uart.write('AT$FORM=0,@T,0,"%VB"\r\n')
        uart.write('AT$FUNC="VRBL",0,150\r\n')
        uart.write('AT$GPOS=2,0\r\n')


#---- main() ----#

lcd.init(freq=15000000)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(0)
sensor.run(1)

fpioa = FPIOA()
fpioa.help(fpioa.UART2_TX)
fpioa.help(fpioa.UART2_RX)
fpioa.set_function(12, fpioa.UART2_TX)
fpioa.set_function(11, fpioa.UART2_RX)
fpioa.set_function(10, fpioa.GPIO0)

uart = UART(UART.UART2, 57600, 8, None, 1, timeout=1000, read_buf_len=4096)
write_str = 'Received\n'
"""
while(True):
     a = uart.readline()
     if(a != None):
        print(a)
        uart.write(write_str)
"""
Example #11
0
from fpioa_manager import *
import os, Maix, lcd, image
from Maix import FPIOA, GPIO
import time

fpioa = FPIOA()

in_pin = 22
out_pin = 23
fpioa.set_function(in_pin, FPIOA.GPIO6)
fpioa.set_function(out_pin, FPIOA.GPIO5)
in_gpio = GPIO(GPIO.GPIO6, GPIO.IN)
out_gpio = GPIO(GPIO.GPIO5, GPIO.OUT)

lcd.init(color=lcd.WHITE)
lcd.draw_string(0, 0, "Testing pins 22(in) 23(out)", lcd.BLACK, lcd.WHITE)

count = 100000
zero = True
while True:
    count = count + 1
    if count >= 100000:
        if zero:
            out_gpio.value(0)
            lcd.draw_string(0, 50, "pin 23 output is: %d" % 0, lcd.BLACK,
                            lcd.WHITE)
            lcd.draw_string(0, 100, "pin 22 reads: %d" % in_gpio.value(),
                            lcd.BLACK, lcd.WHITE)
        else:
            out_gpio.value(1)
            lcd.draw_string(0, 50, "pin 23 output is: %d" % 1, lcd.BLACK,
Example #12
0
from machine import Timer,PWM
import math
import time
import utime
import sensor
import image
import lcd
import time
import random
from Maix import FPIOA
from Maix import GPIO

#button
Fpioa = FPIOA()
Fpioa.set_function(3, FPIOA.GPIO0)
button=GPIO(GPIO.GPIO0,GPIO.IN)

tim1 = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
blue_led = PWM(tim1,500000,0,0)

tim2 = Timer(Timer.TIMER0, Timer.CHANNEL1, mode=Timer.MODE_PWM)
green_led = PWM(tim2, 500000, 0, 1)

tim3 = Timer(Timer.TIMER0, Timer.CHANNEL2, mode=Timer.MODE_PWM)
red_led = PWM(tim3, 500000, 0, 2)

def led_control(r,g,b):
    b_value=b/255*100
    g_value=g/255*100
    r_value=r/255*100
    blue_led.duty(b_value)