diff --git a/docs/psoc6/quickref.rst b/docs/psoc6/quickref.rst index 7db0f60d3952..89b542bceb6f 100644 --- a/docs/psoc6/quickref.rst +++ b/docs/psoc6/quickref.rst @@ -144,6 +144,7 @@ There's a higher-level abstraction :ref:`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 @@ -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: :: diff --git a/ports/psoc6/drivers/machine/psoc6_pwm.h b/ports/psoc6/drivers/machine/psoc6_pwm.h deleted file mode 100644 index dbda21ddd015..000000000000 --- a/ports/psoc6/drivers/machine/psoc6_pwm.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MICROPY_INCLUDED_PSOC6_PWM_H -#define MICROPY_INCLUDED_PSOC6_PWM_H - -// mpy includes -#include "py/runtime.h" - -// MTB includes -#include "cyhal.h" - -typedef struct _machine_pwm_obj_t { - mp_obj_base_t base; - cyhal_pwm_t pwm_obj; - bool active; - uint8_t pin; - uint32_t fz; - uint8_t duty_type; - mp_int_t duty; - bool invert; -} machine_pwm_obj_t; - -cy_rslt_t pwm_freq_duty_set(cyhal_pwm_t *pwm_obj, uint32_t fz, float duty_cycle); -cy_rslt_t pwm_start(cyhal_pwm_t *pwm_obj); -cy_rslt_t pwm_init(machine_pwm_obj_t *machine_pwm_obj); -cy_rslt_t pwm_duty_set_ns(cyhal_pwm_t *pwm_obj, uint32_t fz, uint32_t pulse_width); -cy_rslt_t pwm_advanced_init(machine_pwm_obj_t *machine_pwm_obj); -void pwm_deinit(cyhal_pwm_t *pwm_obj); - -#endif // MICROPY_INCLUDED_PSOC6_PWM_H diff --git a/ports/psoc6/modules/machine/machine_pwm.c b/ports/psoc6/modules/machine/machine_pwm.c index a7acf8a93549..41857a1418d0 100644 --- a/ports/psoc6/modules/machine/machine_pwm.c +++ b/ports/psoc6/modules/machine/machine_pwm.c @@ -1,4 +1,4 @@ -#include "py/runtime.h" + #include "py/runtime.h" #include "py/mphal.h" #include "modmachine.h" diff --git a/tests/psoc6/dut/adc.py b/tests/psoc6/dut/adc.py new file mode 100644 index 000000000000..8ab83f904972 --- /dev/null +++ b/tests/psoc6/dut/adc.py @@ -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) diff --git a/tests/psoc6/dut/adc.py.exp b/tests/psoc6/dut/adc.py.exp new file mode 100644 index 000000000000..afa101f1d094 --- /dev/null +++ b/tests/psoc6/dut/adc.py.exp @@ -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 diff --git a/tests/psoc6/dut/i2c_hard.py b/tests/psoc6/dut/i2c_hard.py new file mode 100644 index 000000000000..5e91fcf7c7bd --- /dev/null +++ b/tests/psoc6/dut/i2c_hard.py @@ -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 diff --git a/tests/psoc6/dut/i2c_hard.py.exp b/tests/psoc6/dut/i2c_hard.py.exp new file mode 100644 index 000000000000..d3a1e6a7aa50 --- /dev/null +++ b/tests/psoc6/dut/i2c_hard.py.exp @@ -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' diff --git a/tests/psoc6/dut/i2c_soft.py b/tests/psoc6/dut/i2c_soft.py new file mode 100644 index 000000000000..e437a3f1e15f --- /dev/null +++ b/tests/psoc6/dut/i2c_soft.py @@ -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 diff --git a/tests/psoc6/dut/i2c_soft.py.exp b/tests/psoc6/dut/i2c_soft.py.exp new file mode 100644 index 000000000000..d3a1e6a7aa50 --- /dev/null +++ b/tests/psoc6/dut/i2c_soft.py.exp @@ -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' diff --git a/tests/psoc6/dut/pwm.py b/tests/psoc6/dut/pwm.py new file mode 100644 index 000000000000..23ec0830b123 --- /dev/null +++ b/tests/psoc6/dut/pwm.py @@ -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) diff --git a/tests/psoc6/dut/pwm.py.exp b/tests/psoc6/dut/pwm.py.exp new file mode 100644 index 000000000000..0ca95142bb71 --- /dev/null +++ b/tests/psoc6/dut/pwm.py.exp @@ -0,0 +1 @@ +True