Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finishing merge with from mbs #104

Merged
merged 10 commits into from
Nov 7, 2023
2 changes: 1 addition & 1 deletion docs/psoc6/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ There's a higher-level abstraction :ref:`machine.Signal <machine.Signal>`
which can be used to invert a pin. Useful for illuminating active-low LEDs
using ``on()`` or ``value(1)``.


Software I2C bus
----------------
Software I2C (using bit-banging) works on all output-capable pins, and is
Expand Down Expand Up @@ -301,7 +302,6 @@ Security modes constants:
.. note::
Power modes configuration not implemented.


Here is a function you can run (or put in your boot.py file) to automatically connect to your WiFi network:

::
Expand Down
28 changes: 0 additions & 28 deletions ports/psoc6/drivers/machine/psoc6_pwm.h

This file was deleted.

2 changes: 1 addition & 1 deletion ports/psoc6/modules/machine/machine_pwm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "py/runtime.h"
#include "py/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"

Expand Down
26 changes: 26 additions & 0 deletions tests/psoc6/dut/adc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### ADC Functional test
""" Setup description:
Connect 3.3V input to adc_pin0 and 0V input to adc_pin1. With the setup done, run the test.

*Known issue: The max output voltage currently is ~2.3V for 3.3V input.
"""
import os
import time
from machine import PWM, ADC

# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
adc_pin0 = "P10_0"
adc_pin1 = "P10_1"
elif "CY8CPROTO-063-BLE" in machine:
adc_pin0 = "P10_0"
adc_pin1 = "P10_1"

adc0 = ADC(adc_pin0, sample_ns=1000)
adc1 = ADC(adc_pin1, sample_ns=1000)

print("Voltage (in microvolts) on pin", adc_pin0, "is max: ", adc0.read_uv() > 1000000)
print("Voltage (raw count) on pin", adc_pin0, "is max: ", adc0.read_u16() > 500)
print("Voltage (in microvolts) on pin", adc_pin1, "is max: ", adc1.read_uv() < 1000000)
print("Voltage (raw count) on pin", adc_pin1, "is max: ", adc1.read_u16() < 500)
4 changes: 4 additions & 0 deletions tests/psoc6/dut/adc.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Voltage (in microvolts) on pin P10_0 is max: True
Voltage (raw count) on pin P10_0 is max: True
Voltage (in microvolts) on pin P10_1 is max: True
Voltage (raw count) on pin P10_1 is max: True
28 changes: 28 additions & 0 deletions tests/psoc6/dut/i2c_hard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### I2C

from machine import I2C
import time
import os

# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
scl_pin = "P6_0"
sda_pin = "P6_1"
elif "CY8CPROTO-063-BLE" in machine:
scl_pin = "P6_4"
sda_pin = "P6_5"

i2c = I2C(0, scl=scl_pin, sda=sda_pin, freq=400000)
addr = i2c.scan()
master_data = b"\x01\x00\x17"
counter = 0

while counter != 5:
i2c.writeto(addr[0], master_data)
time.sleep(1)
slave_data = i2c.readfrom(addr[0], 3)
print("Slave sent data: ", slave_data)
master_data = slave_data
time.sleep(1)
counter = counter + 1
5 changes: 5 additions & 0 deletions tests/psoc6/dut/i2c_hard.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Slave sent data: b'\x01\xff\x17'
Slave sent data: b'\x01\x00\x17'
Slave sent data: b'\x01\xff\x17'
Slave sent data: b'\x01\x00\x17'
Slave sent data: b'\x01\xff\x17'
27 changes: 27 additions & 0 deletions tests/psoc6/dut/i2c_soft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### SoftI2C
import os
from machine import SoftI2C
import time

# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
scl_pin = "P6_0"
sda_pin = "P6_1"
elif "CY8CPROTO-063-BLE" in machine:
scl_pin = "P6_4"
sda_pin = "P6_5"

i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=400000)
addr = i2c.scan()
master_data = b"\x01\x00\x17"
counter = 0

while counter != 5:
i2c.writeto(addr[0], master_data)
time.sleep(1)
slave_data = i2c.readfrom(addr[0], 3)
print("Slave sent data: ", slave_data)
master_data = slave_data
time.sleep(1)
counter = counter + 1
5 changes: 5 additions & 0 deletions tests/psoc6/dut/i2c_soft.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Slave sent data: b'\x01\xff\x17'
Slave sent data: b'\x01\x00\x17'
Slave sent data: b'\x01\xff\x17'
Slave sent data: b'\x01\x00\x17'
Slave sent data: b'\x01\xff\x17'
45 changes: 45 additions & 0 deletions tests/psoc6/dut/pwm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
### PWM - WIP
""" Setup description:
Connect pwm_pin to gpio_pin. PWM signal is generated at 50% duty cycle currently. Every time the level changes, the gpio_pin
is triggered and elapsed tick is calculated. Based on values ton and toff, experimental duty cycle is calculated.

*Known issue: This test will not work for any duty cycle except for 65535 or 0 values since there are fixes required in module.
"""
import os
import time
from machine import PWM, Pin
import time

# Allocate pin based on board
machine = os.uname().machine
if "CY8CPROTO-062-4343W" in machine:
pwm_pin = "P12_0"
gpio_pin = "P13_6"

elif "CY8CPROTO-063-BLE" in machine:
pwm_pin = "P6_2"
gpio_pin = "P5_2"

gpio_flag = 0

input_pin = Pin(gpio_pin, Pin.IN)

t0 = time.ticks_cpu()

pwm = PWM(pwm_pin, freq=10, duty_u16=32768, invert=0)

while gpio_flag != 1:
if input_pin.value() == 1:
gpio_flag = 1
t1 = time.ticks_cpu()
toff = t1 - t0

while gpio_flag != 0:
if input_pin.value() == 0:
gpio_flag = 0
t2 = time.ticks_cpu()
ton = t2 - t1

duty_cycle = (ton / (ton + toff)) * 100

print("Experimental duty cycle(%) = ", duty_cycle)
1 change: 1 addition & 0 deletions tests/psoc6/dut/pwm.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
True
Loading