From 1020fbe299ad73a1a81577cb14e6bceae06673ec Mon Sep 17 00:00:00 2001 From: jaenrig-ifx Date: Mon, 24 Apr 2023 14:26:36 +0200 Subject: [PATCH 01/10] docs: Added docs and docs conf for PSoC6 port. - Added PSoC6 quick reference to docs. - Added sphinx-tabs as install requirement. - Added PSoC6 to topindex templates. Signed-off-by: jaenrig-ifx --- docs/psoc6/mpy-usage.rst | 8 ++++++ docs/psoc6/quickref.rst | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/docs/psoc6/mpy-usage.rst b/docs/psoc6/mpy-usage.rst index cb48d24eb20a..e48629714cb5 100644 --- a/docs/psoc6/mpy-usage.rst +++ b/docs/psoc6/mpy-usage.rst @@ -15,7 +15,11 @@ the USB-UART interface from the on-board debugger. REPL stands for Read Evaluate Print Loop, and is the name given to the interactive MicroPython prompt that you can access on the PSoC6™ board. Using the REPL is by far the easiest way to test out your +<<<<<<< HEAD code and run commands. This is equivalent to running the *python* command (without passing a script) in the command line terminal of your machine. +======= +code and run commands. This is equivalent to running the *python* commmand (without passing a script) in the command line terminal of your machine. +>>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) Use your preferred serial terminal software to connect to the board. Examples of serial terminal tools are `Putty `_, which works for Windows and @@ -81,7 +85,11 @@ The filesystem is described in the section below with some examples. The MicroPython filesystem --------------------------- +<<<<<<< HEAD The PSoC6™ port offers both the ``FAT`` and ``LFS2`` filesystems, implemented in :ref:`MicroPython `. However, given its stability and reliability, the ``LFS2`` filesystem is selected as default. In addition, the filesystem is located, by default on the External Flash which has a capacity of 512 Mb (64 MB). +======= +The PSoC6™ port offers both the ``FAT`` and ``LFS2`` filesystems, implemented in :ref:`MicroPython `. However, given its stabilty and reliability, the ``LFS2`` filesystem is selected as default. In addition, the filesystem is located, by default on the External Flash which has a capacity of 512 Mb (64 MB). +>>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) The filesystem is mounted with the help of frozen scripts, located in the ``ports/psoc6/freeze`` directory. The default mount point of the filesystem is the ``/flash`` directory, which serves as its root. diff --git a/docs/psoc6/quickref.rst b/docs/psoc6/quickref.rst index 7db0f60d3952..652744ac2601 100644 --- a/docs/psoc6/quickref.rst +++ b/docs/psoc6/quickref.rst @@ -140,9 +140,24 @@ Methods Set pin value to its complement. +<<<<<<< HEAD +======= +Constants +^^^^^^^^^ +The following constants are used to configure the pin objects in addition to the ones mentioned in the :mod:`machine.Pin` class. + +.. data:: Pin.STATE_LOW + Pin.STATE_HIGH + + Selects the pin value. + +<<<<<<< HEAD +>>>>>>> 6a6924d9a (docs: Added docs and docs conf for PSoC6 port.) 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)``. +======= +>>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) Software I2C bus ---------------- @@ -243,6 +258,7 @@ The :mod:`network` module See :ref:`network.WLAN ` +<<<<<<< HEAD For some methods and constants, the PSoC6 network port implements certain specialization and slightly different behavior. This is explained in this section. Methods @@ -301,7 +317,49 @@ Security modes constants: .. note:: Power modes configuration not implemented. +<<<<<<< HEAD + +======= +======= +The network module is used to configure the WiFi connection.The WiFi interface for the station mode is only configured for +this port.Create WLAN interface object using :: + + import network + wlan = network.WLAN(network.STA_IF) # create station interface + +Scan for the available wireless networks using +:: + + wlan.scan() + +Scan function returns a list of tuple information about access points +(ssid, bssid, channel, RSSI, security, hidden) .There are 7 levels of security: + + * ``0 - open``, + * ``1 - WEP``, + * ``2 - WPA``, + * ``3 - WPA2``, + * ``4 - WPA2_WPA``, + * ``5 - WPA3``, + * ``6 - WPS``, + * ``7 - Unknown security``. + +These are the other functions available in the network module + +:: + + wlan.active(True) # activate the interface + wlan.scan() # scan for access points + wlan.isconnected() # check if the station is connected to an AP + wlan.connect('ssid', 'key') # connect to an AP + wlan.disconnect() # disconnect from the connected AP + wlan.status() # check the link status and returns 1 for linkup & 0 for linkdown + wlan.ifconfig() # get the interface's IP/netmask/gateway/DNS addresses + + +>>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) +>>>>>>> 6a6924d9a (docs: Added docs and docs conf for PSoC6 port.) Here is a function you can run (or put in your boot.py file) to automatically connect to your WiFi network: :: From 11380610b013b2b6ffb8e7c032b134e0a3b72d13 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Thu, 7 Sep 2023 17:59:50 +0200 Subject: [PATCH 02/10] ports/psoc6: Removed psoc6_pwm driver. Signed-off-by: enriquezgarc --- ports/psoc6/drivers/machine/psoc6_pwm.h | 28 ----------------------- ports/psoc6/modules/machine/machine_pwm.c | 11 +++++++++ 2 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 ports/psoc6/drivers/machine/psoc6_pwm.h 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..a50a3e3edf55 100644 --- a/ports/psoc6/modules/machine/machine_pwm.c +++ b/ports/psoc6/modules/machine/machine_pwm.c @@ -56,6 +56,17 @@ STATIC inline void pwm_pin_free(machine_pwm_obj_t *pwm_obj) { pin_phy_free(pwm_obj->pin); } +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_float_t duty; + bool invert; +} machine_pwm_obj_t; + enum { VALUE_NOT_SET = -1, DUTY_NOT_SET = 0, From e7e4b0c2ad347ac6efe10de9e64fb31e0e59b44a Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Tue, 26 Sep 2023 12:55:59 +0200 Subject: [PATCH 03/10] docs/psoc6/mpy-usage.rst: Fixed merge conflict. Signed-off-by: enriquezgarc --- docs/psoc6/mpy-usage.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/docs/psoc6/mpy-usage.rst b/docs/psoc6/mpy-usage.rst index e48629714cb5..cb48d24eb20a 100644 --- a/docs/psoc6/mpy-usage.rst +++ b/docs/psoc6/mpy-usage.rst @@ -15,11 +15,7 @@ the USB-UART interface from the on-board debugger. REPL stands for Read Evaluate Print Loop, and is the name given to the interactive MicroPython prompt that you can access on the PSoC6™ board. Using the REPL is by far the easiest way to test out your -<<<<<<< HEAD code and run commands. This is equivalent to running the *python* command (without passing a script) in the command line terminal of your machine. -======= -code and run commands. This is equivalent to running the *python* commmand (without passing a script) in the command line terminal of your machine. ->>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) Use your preferred serial terminal software to connect to the board. Examples of serial terminal tools are `Putty `_, which works for Windows and @@ -85,11 +81,7 @@ The filesystem is described in the section below with some examples. The MicroPython filesystem --------------------------- -<<<<<<< HEAD The PSoC6™ port offers both the ``FAT`` and ``LFS2`` filesystems, implemented in :ref:`MicroPython `. However, given its stability and reliability, the ``LFS2`` filesystem is selected as default. In addition, the filesystem is located, by default on the External Flash which has a capacity of 512 Mb (64 MB). -======= -The PSoC6™ port offers both the ``FAT`` and ``LFS2`` filesystems, implemented in :ref:`MicroPython `. However, given its stabilty and reliability, the ``LFS2`` filesystem is selected as default. In addition, the filesystem is located, by default on the External Flash which has a capacity of 512 Mb (64 MB). ->>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) The filesystem is mounted with the help of frozen scripts, located in the ``ports/psoc6/freeze`` directory. The default mount point of the filesystem is the ``/flash`` directory, which serves as its root. From 605878827c4c48c88e3edc470ed51f5d422e73cd Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Thu, 12 Oct 2023 16:19:17 +0200 Subject: [PATCH 04/10] ports/psoc6/../machine_pwm.c: Added deinit and pin phy refactor. Signed-off-by: enriquezgarc --- ports/psoc6/modules/machine/machine_pwm.c | 43 +++++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ports/psoc6/modules/machine/machine_pwm.c b/ports/psoc6/modules/machine/machine_pwm.c index a50a3e3edf55..1d02809eb14f 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" @@ -59,14 +59,51 @@ STATIC inline void pwm_pin_free(machine_pwm_obj_t *pwm_obj) { typedef struct _machine_pwm_obj_t { mp_obj_base_t base; cyhal_pwm_t pwm_obj; - bool active; - uint8_t pin; + machine_pin_phy_obj_t *pin; uint32_t fz; uint8_t duty_type; mp_float_t duty; bool invert; } machine_pwm_obj_t; +static machine_pwm_obj_t *pwm_obj[MAX_PWM_OBJS] = { NULL }; + +STATIC inline machine_pwm_obj_t *pwm_obj_alloc() { + for (uint8_t i = 0; i < MAX_PWM_OBJS; i++) + { + if (pwm_obj[i] == NULL) { + pwm_obj[i] = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type); + return pwm_obj[i]; + } + } + + return NULL; +} + +STATIC inline void pwm_obj_free(machine_pwm_obj_t *pwm_obj_ptr) { + for (uint8_t i = 0; i < MAX_PWM_OBJS; i++) + { + if (pwm_obj[i] == pwm_obj_ptr) { + pwm_obj[i] = NULL; + } + } +} + +STATIC inline void pwm_pin_alloc(machine_pwm_obj_t *pwm_obj, mp_obj_t pin_name) { + machine_pin_phy_obj_t *pin = pin_phy_realloc(pin_name, PIN_PHY_FUNC_PWM); + + if (pin == NULL) { + size_t slen; + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("PWM pin (%s) not found !"), mp_obj_str_get_data(pin_name, &slen)); + } + + pwm_obj->pin = pin; +} + +STATIC inline void pwm_pin_free(machine_pwm_obj_t *pwm_obj) { + pin_phy_free(pwm_obj->pin); +} + enum { VALUE_NOT_SET = -1, DUTY_NOT_SET = 0, From fd8282fa2a89cc2d5b932b44885e6dc43cdf313c Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Mon, 30 Oct 2023 05:18:14 +0530 Subject: [PATCH 05/10] tests/psoc6/dut: Adding functional tests for psoc6. Signed-off-by: NikhitaR-IFX --- tests/psoc6/dut/adc.py | 27 +++++++++++++ tests/psoc6/dut/adc.py.exp | 6 +++ tests/psoc6/dut/i2c_hard.py | 28 ++++++++++++++ tests/psoc6/dut/i2c_hard.py.exp | 5 +++ tests/psoc6/dut/i2c_soft.py | 28 ++++++++++++++ tests/psoc6/dut/i2c_soft.py.exp | 5 +++ tests/psoc6/dut/pwm.py | 68 +++++++++++++++++++++++++++++++++ tests/psoc6/dut/pwm.py.exp | 26 +++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 tests/psoc6/dut/adc.py create mode 100644 tests/psoc6/dut/adc.py.exp create mode 100644 tests/psoc6/dut/i2c_hard.py create mode 100644 tests/psoc6/dut/i2c_hard.py.exp create mode 100644 tests/psoc6/dut/i2c_soft.py create mode 100644 tests/psoc6/dut/i2c_soft.py.exp create mode 100644 tests/psoc6/dut/pwm.py create mode 100644 tests/psoc6/dut/pwm.py.exp diff --git a/tests/psoc6/dut/adc.py b/tests/psoc6/dut/adc.py new file mode 100644 index 000000000000..ee16b6d55d90 --- /dev/null +++ b/tests/psoc6/dut/adc.py @@ -0,0 +1,27 @@ +### ADC +import os +import time +from machine import PWM, ADC + +# Allocate pin based on board +machine = os.uname().machine +if "CY8CPROTO-062-4343W" in machine: + pin_name = "P12_0" + adc_pin = "P10_0" +elif "CY8CPROTO-063-BLE" in machine: + pin_name = "P6_2" + adc_pin = "P10_0" + +adc = ADC(adc_pin, sample_ns=1000) +pwm = PWM(pin_name, freq=1000, duty_u16=65535, invert =0) + +print("Initial Voltage (microvolts) is max: ",adc.read_uv()>1500) +print("Initial Voltage (raw data) is max: ",adc.read_u16()>50) +pwm.duty_u16(0) +time.sleep_ms(100) +print("Off signal Voltage (microvolts) is ~0 : ",adc.read_uv()<1500) +print("Off signal Voltage (raw data) is ~0 : ",adc.read_u16()<50) +pwm.duty_u16(65535) +time.sleep_ms(100) +print("On signal Voltage (microvolts) is max: ",adc.read_uv()>1500) +print("On signal Voltage (raw data) is max: ",adc.read_u16()>50) diff --git a/tests/psoc6/dut/adc.py.exp b/tests/psoc6/dut/adc.py.exp new file mode 100644 index 000000000000..9766a10ff761 --- /dev/null +++ b/tests/psoc6/dut/adc.py.exp @@ -0,0 +1,6 @@ +Initial Voltage (microvolts) is max: True +Initial Voltage (raw data) is max: True +Off signal Voltage (microvolts) is ~0 : True +Off signal Voltage (raw data) is ~0 : True +On signal Voltage (microvolts) is max: True +On signal Voltage (raw data) 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..1f45cee576e4 --- /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..667b8c6b7088 --- /dev/null +++ b/tests/psoc6/dut/i2c_soft.py @@ -0,0 +1,28 @@ +#### 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..1d6bd854cc37 --- /dev/null +++ b/tests/psoc6/dut/pwm.py @@ -0,0 +1,68 @@ +### PWM +import os +import time +from machine import PWM + +# Allocate pin based on board +machine = os.uname().machine +if "CY8CPROTO-062-4343W" in machine: + pin_name = "P12_0" +elif "CY8CPROTO-063-BLE" in machine: + pin_name = "P6_2" + +def generate_new_signal(pwm_obj, freq, duty_cycle_u16): + pwm_obj.freq(freq) + pwm_obj.duty_u16(duty_cycle_u16) + +pwm = PWM(pin_name, freq=50, duty_u16=32768, invert =0) + +print("Initial freq: ", pwm.freq()) +print("Initial duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 1Hz and Duty cycle of 25% +generate_new_signal(pwm, 1, 16384) +print("Signal with freq = 1Hz and Duty cycle of 25%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 1Hz and Duty cycle of 50% +generate_new_signal(pwm, 1, 32768) +print("Signal with freq = 1Hz and Duty cycle of 50%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 1Hz and Duty cycle of 75% +generate_new_signal(pwm, 1, 49151) +print("Signal with freq = 1Hz and Duty cycle of 75%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 1Hz and Duty cycle of 100% +generate_new_signal(pwm, 1, 65535) +print("Signal with freq = 1Hz and Duty cycle of 100%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 25Hz and Duty cycle of 25% +generate_new_signal(pwm, 25, 16384) +print("Signal with freq = 25Hz and Duty cycle of 250%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 50Hz and Duty cycle of 50% +generate_new_signal(pwm, 50, 32768) +print("Signal with freq = 50Hz and Duty cycle of 50%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 75Hz and Duty cycle of 75% +generate_new_signal(pwm, 75, 49151) +print("Signal with freq = 75Hz and Duty cycle of 75%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) + +# Generate signal with freq = 100Hz and Duty cycle of 100% +generate_new_signal(pwm, 100, 65535) +print("Signal with freq = 100Hz and Duty cycle of 100%") +print("Current freq: ", pwm.freq()) +print("Current duty cycle: ", pwm.duty_u16()) \ No newline at end of file diff --git a/tests/psoc6/dut/pwm.py.exp b/tests/psoc6/dut/pwm.py.exp new file mode 100644 index 000000000000..9743a701cec2 --- /dev/null +++ b/tests/psoc6/dut/pwm.py.exp @@ -0,0 +1,26 @@ +Initial freq: 50 +Initial duty cycle: 32768.0 +Signal with freq = 1Hz and Duty cycle of 25% +Current freq: 1 +Current duty cycle: 16384.0 +Signal with freq = 1Hz and Duty cycle of 50% +Current freq: 1 +Current duty cycle: 32768.0 +Signal with freq = 1Hz and Duty cycle of 75% +Current freq: 1 +Current duty cycle: 49151.0 +Signal with freq = 1Hz and Duty cycle of 100% +Current freq: 1 +Current duty cycle: 65535.0 +Signal with freq = 25Hz and Duty cycle of 250% +Current freq: 25 +Current duty cycle: 16384.0 +Signal with freq = 50Hz and Duty cycle of 50% +Current freq: 50 +Current duty cycle: 32768.0 +Signal with freq = 75Hz and Duty cycle of 75% +Current freq: 75 +Current duty cycle: 49151.0 +Signal with freq = 100Hz and Duty cycle of 100% +Current freq: 100 +Current duty cycle: 65535.0 From 56263a85d043519f537305eea5ca3306997018c2 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Mon, 6 Nov 2023 14:15:46 +0530 Subject: [PATCH 06/10] tests/psoc6/dut: Adding func tests for adc and pwm. Signed-off-by: NikhitaR-IFX --- tests/psoc6/dut/adc.py | 33 ++++++++------- tests/psoc6/dut/adc.py.exp | 10 ++--- tests/psoc6/dut/pwm.py | 83 ++++++++++++++------------------------ tests/psoc6/dut/pwm.py.exp | 27 +------------ 4 files changed, 51 insertions(+), 102 deletions(-) diff --git a/tests/psoc6/dut/adc.py b/tests/psoc6/dut/adc.py index ee16b6d55d90..6e70e267a09f 100644 --- a/tests/psoc6/dut/adc.py +++ b/tests/psoc6/dut/adc.py @@ -1,4 +1,9 @@ -### ADC +### 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 @@ -6,22 +11,16 @@ # Allocate pin based on board machine = os.uname().machine if "CY8CPROTO-062-4343W" in machine: - pin_name = "P12_0" - adc_pin = "P10_0" + adc_pin0 = "P10_0" + adc_pin1 = "P10_1" elif "CY8CPROTO-063-BLE" in machine: - pin_name = "P6_2" - adc_pin = "P10_0" + adc_pin0 = "P10_0" + adc_pin1 = "P10_1" -adc = ADC(adc_pin, sample_ns=1000) -pwm = PWM(pin_name, freq=1000, duty_u16=65535, invert =0) +adc0 = ADC(adc_pin0, sample_ns=1000) +adc1 = ADC(adc_pin1, sample_ns=1000) -print("Initial Voltage (microvolts) is max: ",adc.read_uv()>1500) -print("Initial Voltage (raw data) is max: ",adc.read_u16()>50) -pwm.duty_u16(0) -time.sleep_ms(100) -print("Off signal Voltage (microvolts) is ~0 : ",adc.read_uv()<1500) -print("Off signal Voltage (raw data) is ~0 : ",adc.read_u16()<50) -pwm.duty_u16(65535) -time.sleep_ms(100) -print("On signal Voltage (microvolts) is max: ",adc.read_uv()>1500) -print("On signal Voltage (raw data) is max: ",adc.read_u16()>50) +print("Volatge (in microvolts) on pin", adc_pin0, "is max: ", adc0.read_uv() > 1000000) +print("Volatge (raw count) on pin", adc_pin0, "is max: ", adc0.read_u16() > 500) +print("Volatge (in microvolts) on pin", adc_pin1, "is max: ", adc1.read_uv() < 1000000) +print("Volatge (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 index 9766a10ff761..476dbee62dd2 100644 --- a/tests/psoc6/dut/adc.py.exp +++ b/tests/psoc6/dut/adc.py.exp @@ -1,6 +1,4 @@ -Initial Voltage (microvolts) is max: True -Initial Voltage (raw data) is max: True -Off signal Voltage (microvolts) is ~0 : True -Off signal Voltage (raw data) is ~0 : True -On signal Voltage (microvolts) is max: True -On signal Voltage (raw data) is max: True +Volatge (in microvolts) on pin P10_0 is max: True +Volatge (raw count) on pin P10_0 is max: True +Volatge (in microvolts) on pin P10_1 is max: True +Volatge (raw count) on pin P10_1 is max: True diff --git a/tests/psoc6/dut/pwm.py b/tests/psoc6/dut/pwm.py index 1d6bd854cc37..23ec0830b123 100644 --- a/tests/psoc6/dut/pwm.py +++ b/tests/psoc6/dut/pwm.py @@ -1,68 +1,45 @@ -### PWM +### 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 +from machine import PWM, Pin +import time # Allocate pin based on board machine = os.uname().machine if "CY8CPROTO-062-4343W" in machine: - pin_name = "P12_0" -elif "CY8CPROTO-063-BLE" in machine: - pin_name = "P6_2" + pwm_pin = "P12_0" + gpio_pin = "P13_6" -def generate_new_signal(pwm_obj, freq, duty_cycle_u16): - pwm_obj.freq(freq) - pwm_obj.duty_u16(duty_cycle_u16) - -pwm = PWM(pin_name, freq=50, duty_u16=32768, invert =0) - -print("Initial freq: ", pwm.freq()) -print("Initial duty cycle: ", pwm.duty_u16()) +elif "CY8CPROTO-063-BLE" in machine: + pwm_pin = "P6_2" + gpio_pin = "P5_2" -# Generate signal with freq = 1Hz and Duty cycle of 25% -generate_new_signal(pwm, 1, 16384) -print("Signal with freq = 1Hz and Duty cycle of 25%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +gpio_flag = 0 -# Generate signal with freq = 1Hz and Duty cycle of 50% -generate_new_signal(pwm, 1, 32768) -print("Signal with freq = 1Hz and Duty cycle of 50%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +input_pin = Pin(gpio_pin, Pin.IN) -# Generate signal with freq = 1Hz and Duty cycle of 75% -generate_new_signal(pwm, 1, 49151) -print("Signal with freq = 1Hz and Duty cycle of 75%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +t0 = time.ticks_cpu() -# Generate signal with freq = 1Hz and Duty cycle of 100% -generate_new_signal(pwm, 1, 65535) -print("Signal with freq = 1Hz and Duty cycle of 100%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +pwm = PWM(pwm_pin, freq=10, duty_u16=32768, invert=0) -# Generate signal with freq = 25Hz and Duty cycle of 25% -generate_new_signal(pwm, 25, 16384) -print("Signal with freq = 25Hz and Duty cycle of 250%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +while gpio_flag != 1: + if input_pin.value() == 1: + gpio_flag = 1 + t1 = time.ticks_cpu() + toff = t1 - t0 -# Generate signal with freq = 50Hz and Duty cycle of 50% -generate_new_signal(pwm, 50, 32768) -print("Signal with freq = 50Hz and Duty cycle of 50%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +while gpio_flag != 0: + if input_pin.value() == 0: + gpio_flag = 0 + t2 = time.ticks_cpu() + ton = t2 - t1 -# Generate signal with freq = 75Hz and Duty cycle of 75% -generate_new_signal(pwm, 75, 49151) -print("Signal with freq = 75Hz and Duty cycle of 75%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) +duty_cycle = (ton / (ton + toff)) * 100 -# Generate signal with freq = 100Hz and Duty cycle of 100% -generate_new_signal(pwm, 100, 65535) -print("Signal with freq = 100Hz and Duty cycle of 100%") -print("Current freq: ", pwm.freq()) -print("Current duty cycle: ", pwm.duty_u16()) \ No newline at end of file +print("Experimental duty cycle(%) = ", duty_cycle) diff --git a/tests/psoc6/dut/pwm.py.exp b/tests/psoc6/dut/pwm.py.exp index 9743a701cec2..0ca95142bb71 100644 --- a/tests/psoc6/dut/pwm.py.exp +++ b/tests/psoc6/dut/pwm.py.exp @@ -1,26 +1 @@ -Initial freq: 50 -Initial duty cycle: 32768.0 -Signal with freq = 1Hz and Duty cycle of 25% -Current freq: 1 -Current duty cycle: 16384.0 -Signal with freq = 1Hz and Duty cycle of 50% -Current freq: 1 -Current duty cycle: 32768.0 -Signal with freq = 1Hz and Duty cycle of 75% -Current freq: 1 -Current duty cycle: 49151.0 -Signal with freq = 1Hz and Duty cycle of 100% -Current freq: 1 -Current duty cycle: 65535.0 -Signal with freq = 25Hz and Duty cycle of 250% -Current freq: 25 -Current duty cycle: 16384.0 -Signal with freq = 50Hz and Duty cycle of 50% -Current freq: 50 -Current duty cycle: 32768.0 -Signal with freq = 75Hz and Duty cycle of 75% -Current freq: 75 -Current duty cycle: 49151.0 -Signal with freq = 100Hz and Duty cycle of 100% -Current freq: 100 -Current duty cycle: 65535.0 +True From 104a59bdf77fb52963cc389c625a031d572884bf Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Mon, 6 Nov 2023 15:02:22 +0530 Subject: [PATCH 07/10] tests/psoc6/dut: Codeformatting i2c tests. Signed-off-by: NikhitaR-IFX --- tests/psoc6/dut/i2c_hard.py | 8 ++++---- tests/psoc6/dut/i2c_soft.py | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/psoc6/dut/i2c_hard.py b/tests/psoc6/dut/i2c_hard.py index 1f45cee576e4..5e91fcf7c7bd 100644 --- a/tests/psoc6/dut/i2c_hard.py +++ b/tests/psoc6/dut/i2c_hard.py @@ -13,16 +13,16 @@ scl_pin = "P6_4" sda_pin = "P6_5" -i2c = I2C(0,scl=scl_pin,sda=sda_pin,freq=400000) +i2c = I2C(0, scl=scl_pin, sda=sda_pin, freq=400000) addr = i2c.scan() -master_data = b'\x01\x00\x17' +master_data = b"\x01\x00\x17" counter = 0 -while(counter!=5): +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 + counter = counter + 1 diff --git a/tests/psoc6/dut/i2c_soft.py b/tests/psoc6/dut/i2c_soft.py index 667b8c6b7088..e437a3f1e15f 100644 --- a/tests/psoc6/dut/i2c_soft.py +++ b/tests/psoc6/dut/i2c_soft.py @@ -14,15 +14,14 @@ i2c = SoftI2C(scl=scl_pin, sda=sda_pin, freq=400000) addr = i2c.scan() -master_data = b'\x01\x00\x17' +master_data = b"\x01\x00\x17" counter = 0 -while(counter!=5): +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 - + counter = counter + 1 From a4728f6227179a5d3a005c5ca2627820a9cc21b7 Mon Sep 17 00:00:00 2001 From: NikhitaR-IFX Date: Mon, 6 Nov 2023 17:50:23 +0530 Subject: [PATCH 08/10] tests/psoc6/dut: Fixing typo. Signed-off-by: NikhitaR-IFX --- tests/psoc6/dut/adc.py | 8 ++++---- tests/psoc6/dut/adc.py.exp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/psoc6/dut/adc.py b/tests/psoc6/dut/adc.py index 6e70e267a09f..8ab83f904972 100644 --- a/tests/psoc6/dut/adc.py +++ b/tests/psoc6/dut/adc.py @@ -20,7 +20,7 @@ adc0 = ADC(adc_pin0, sample_ns=1000) adc1 = ADC(adc_pin1, sample_ns=1000) -print("Volatge (in microvolts) on pin", adc_pin0, "is max: ", adc0.read_uv() > 1000000) -print("Volatge (raw count) on pin", adc_pin0, "is max: ", adc0.read_u16() > 500) -print("Volatge (in microvolts) on pin", adc_pin1, "is max: ", adc1.read_uv() < 1000000) -print("Volatge (raw count) on pin", adc_pin1, "is max: ", adc1.read_u16() < 500) +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 index 476dbee62dd2..afa101f1d094 100644 --- a/tests/psoc6/dut/adc.py.exp +++ b/tests/psoc6/dut/adc.py.exp @@ -1,4 +1,4 @@ -Volatge (in microvolts) on pin P10_0 is max: True -Volatge (raw count) on pin P10_0 is max: True -Volatge (in microvolts) on pin P10_1 is max: True -Volatge (raw count) on pin P10_1 is max: True +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 From cbdda7a50cbec13df2cdbb02ebdcf5ffa75cb9d5 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Tue, 7 Nov 2023 10:35:18 +0100 Subject: [PATCH 09/10] docs/psoc6/quickref.rst: Cleaned merge conflict guards. Signed-off-by: enriquezgarc --- docs/psoc6/quickref.rst | 60 +---------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/docs/psoc6/quickref.rst b/docs/psoc6/quickref.rst index 652744ac2601..89b542bceb6f 100644 --- a/docs/psoc6/quickref.rst +++ b/docs/psoc6/quickref.rst @@ -140,24 +140,10 @@ Methods Set pin value to its complement. -<<<<<<< HEAD -======= -Constants -^^^^^^^^^ -The following constants are used to configure the pin objects in addition to the ones mentioned in the :mod:`machine.Pin` class. - -.. data:: Pin.STATE_LOW - Pin.STATE_HIGH - - Selects the pin value. - -<<<<<<< HEAD ->>>>>>> 6a6924d9a (docs: Added docs and docs conf for PSoC6 port.) 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)``. -======= ->>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) + Software I2C bus ---------------- @@ -258,7 +244,6 @@ The :mod:`network` module See :ref:`network.WLAN ` -<<<<<<< HEAD For some methods and constants, the PSoC6 network port implements certain specialization and slightly different behavior. This is explained in this section. Methods @@ -317,49 +302,6 @@ Security modes constants: .. note:: Power modes configuration not implemented. -<<<<<<< HEAD - -======= -======= -The network module is used to configure the WiFi connection.The WiFi interface for the station mode is only configured for -this port.Create WLAN interface object using :: - - import network - wlan = network.WLAN(network.STA_IF) # create station interface - -Scan for the available wireless networks using - -:: - - wlan.scan() - -Scan function returns a list of tuple information about access points -(ssid, bssid, channel, RSSI, security, hidden) .There are 7 levels of security: - - * ``0 - open``, - * ``1 - WEP``, - * ``2 - WPA``, - * ``3 - WPA2``, - * ``4 - WPA2_WPA``, - * ``5 - WPA3``, - * ``6 - WPS``, - * ``7 - Unknown security``. - -These are the other functions available in the network module - -:: - - wlan.active(True) # activate the interface - wlan.scan() # scan for access points - wlan.isconnected() # check if the station is connected to an AP - wlan.connect('ssid', 'key') # connect to an AP - wlan.disconnect() # disconnect from the connected AP - wlan.status() # check the link status and returns 1 for linkup & 0 for linkdown - wlan.ifconfig() # get the interface's IP/netmask/gateway/DNS addresses - - ->>>>>>> 57a502306 (docs: Added docs and docs conf for PSoC6 port.) ->>>>>>> 6a6924d9a (docs: Added docs and docs conf for PSoC6 port.) Here is a function you can run (or put in your boot.py file) to automatically connect to your WiFi network: :: From 83ce5fe0e6fc1cb5260a7cb0297c2b616e760057 Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Tue, 7 Nov 2023 10:44:30 +0100 Subject: [PATCH 10/10] ports/psoc6/machine_pwm.c: Resolving merge conflicts. Signed-off-by: enriquezgarc --- ports/psoc6/modules/machine/machine_pwm.c | 48 ----------------------- 1 file changed, 48 deletions(-) diff --git a/ports/psoc6/modules/machine/machine_pwm.c b/ports/psoc6/modules/machine/machine_pwm.c index 1d02809eb14f..41857a1418d0 100644 --- a/ports/psoc6/modules/machine/machine_pwm.c +++ b/ports/psoc6/modules/machine/machine_pwm.c @@ -56,54 +56,6 @@ STATIC inline void pwm_pin_free(machine_pwm_obj_t *pwm_obj) { pin_phy_free(pwm_obj->pin); } -typedef struct _machine_pwm_obj_t { - mp_obj_base_t base; - cyhal_pwm_t pwm_obj; - machine_pin_phy_obj_t *pin; - uint32_t fz; - uint8_t duty_type; - mp_float_t duty; - bool invert; -} machine_pwm_obj_t; - -static machine_pwm_obj_t *pwm_obj[MAX_PWM_OBJS] = { NULL }; - -STATIC inline machine_pwm_obj_t *pwm_obj_alloc() { - for (uint8_t i = 0; i < MAX_PWM_OBJS; i++) - { - if (pwm_obj[i] == NULL) { - pwm_obj[i] = mp_obj_malloc(machine_pwm_obj_t, &machine_pwm_type); - return pwm_obj[i]; - } - } - - return NULL; -} - -STATIC inline void pwm_obj_free(machine_pwm_obj_t *pwm_obj_ptr) { - for (uint8_t i = 0; i < MAX_PWM_OBJS; i++) - { - if (pwm_obj[i] == pwm_obj_ptr) { - pwm_obj[i] = NULL; - } - } -} - -STATIC inline void pwm_pin_alloc(machine_pwm_obj_t *pwm_obj, mp_obj_t pin_name) { - machine_pin_phy_obj_t *pin = pin_phy_realloc(pin_name, PIN_PHY_FUNC_PWM); - - if (pin == NULL) { - size_t slen; - mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("PWM pin (%s) not found !"), mp_obj_str_get_data(pin_name, &slen)); - } - - pwm_obj->pin = pin; -} - -STATIC inline void pwm_pin_free(machine_pwm_obj_t *pwm_obj) { - pin_phy_free(pwm_obj->pin); -} - enum { VALUE_NOT_SET = -1, DUTY_NOT_SET = 0,