├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── images └── pynq_hackathon_hw.png ├── pynq_peripherals ├── __init__.py ├── apps │ ├── app0_plant_monitoring_system │ │ └── notebooks │ │ │ ├── images │ │ │ └── dry_arduino.png │ │ │ └── plant_monitoring_system.ipynb │ ├── app1_room_control_system │ │ └── notebooks │ │ │ ├── images │ │ │ ├── rcs_ctl.png │ │ │ ├── room_clip.png │ │ │ └── room_control.png │ │ │ └── room_control_system.ipynb │ ├── app2_led_strings │ │ └── notebooks │ │ │ ├── images │ │ │ └── IMG_2204.jpg │ │ │ └── led_strings.ipynb │ ├── app3_voice_enabled_room_control_system │ │ └── notebooks │ │ │ ├── data │ │ │ ├── check_internet.mp3 │ │ │ └── room.png │ │ │ └── voice_enabled_room_control_system.ipynb │ ├── app4_automatic_door_control_and_motion_logger │ │ └── notebooks │ │ │ ├── automatic_door_control_and_motion_logger.ipynb │ │ │ └── images │ │ │ └── door_control.png │ └── app5_pynq_car │ │ └── notebooks │ │ ├── images │ │ ├── BlackLight.png │ │ ├── map.png │ │ ├── motor_system.png │ │ ├── pynq_car.jpg │ │ └── sensor_connection.png │ │ └── pynq_car.ipynb ├── cli.py ├── modules │ ├── analog │ │ ├── include │ │ │ └── analog.h │ │ └── src │ │ │ └── analog.c │ ├── geared_motor │ │ ├── include │ │ │ └── geared_motor.h │ │ ├── notebooks │ │ │ └── geared_motor.ipynb │ │ └── src │ │ │ └── geared_motor.c │ ├── grove_adc │ │ ├── include │ │ │ └── grove_adc.h │ │ ├── notebooks │ │ │ └── grove_adc.ipynb │ │ └── src │ │ │ └── grove_adc.c │ ├── grove_barometer │ │ ├── include │ │ │ ├── grove_barometer.h │ │ │ └── grove_barometer_hw.h │ │ ├── notebooks │ │ │ └── grove_barometer.ipynb │ │ └── src │ │ │ └── grove_barometer.c │ ├── grove_buzzer │ │ ├── include │ │ │ └── grove_buzzer.h │ │ ├── notebooks │ │ │ └── grove_buzzer.ipynb │ │ └── src │ │ │ └── grove_buzzer.c │ ├── grove_capacitive_soil_moisture │ │ ├── include │ │ │ └── grove_capacitive_soil_moisture.h │ │ ├── notebooks │ │ │ └── grove_capacitive_soil_moisture.ipynb │ │ └── src │ │ │ └── grove_capacitive_soil_moisture.c │ ├── grove_envsensor │ │ ├── include │ │ │ ├── grove_envsensor.h │ │ │ └── grove_envsensor_hw.h │ │ ├── notebooks │ │ │ └── grove_envsensor.ipynb │ │ └── src │ │ │ └── grove_envsensor.c │ ├── grove_gesture │ │ ├── include │ │ │ ├── grove_gesture.h │ │ │ └── grove_gesture_hw.h │ │ ├── notebooks │ │ │ └── grove_gesture.ipynb │ │ └── src │ │ │ └── grove_gesture.c │ ├── grove_imu │ │ ├── include │ │ │ ├── grove_imu.h │ │ │ ├── grove_imu_constants.h │ │ │ └── grove_imu_hw.h │ │ ├── notebooks │ │ │ └── grove_imu.ipynb │ │ └── src │ │ │ └── grove_imu.c │ ├── grove_interfaces │ │ ├── include │ │ │ ├── grove_constants.h │ │ │ └── grove_interfaces.h │ │ └── src │ │ │ └── grove_interfaces.c │ ├── grove_joystick │ │ ├── include │ │ │ └── grove_joystick.h │ │ ├── notebooks │ │ │ └── grove_joystick.ipynb │ │ └── src │ │ │ └── grove_joystick.c │ ├── grove_led_stick │ │ ├── include │ │ │ └── grove_led_stick.h │ │ ├── notebooks │ │ │ └── grove_led_stick.ipynb │ │ └── src │ │ │ └── grove_led_stick.c │ ├── grove_ledbar │ │ ├── include │ │ │ └── grove_ledbar.h │ │ ├── notebooks │ │ │ └── grove_ledbar.ipynb │ │ └── src │ │ │ └── grove_ledbar.c │ ├── grove_lgcp │ │ ├── include │ │ │ ├── grove_lgcp.h │ │ │ └── grove_lgcp_hw.h │ │ ├── notebooks │ │ │ └── grove_lgcp.ipynb │ │ └── src │ │ │ └── grove_lgcp.c │ ├── grove_light │ │ ├── include │ │ │ └── grove_light.h │ │ ├── notebooks │ │ │ └── grove_light.ipynb │ │ └── src │ │ │ └── grove_light.c │ ├── grove_line_finder │ │ ├── include │ │ │ └── grove_line_finder.h │ │ ├── notebooks │ │ │ └── grove_line_finder.ipynb │ │ └── src │ │ │ └── grove_line_finder.c │ ├── grove_oled │ │ ├── include │ │ │ ├── grove_oled.h │ │ │ └── grove_oled_hw.h │ │ ├── notebooks │ │ │ └── grove_oled.ipynb │ │ └── src │ │ │ └── grove_oled.c │ ├── grove_ph │ │ ├── include │ │ │ └── grove_ph.h │ │ ├── notebooks │ │ │ └── grove_ph.ipynb │ │ └── src │ │ │ └── grove_ph.c │ ├── grove_pir │ │ ├── include │ │ │ └── grove_pir.h │ │ ├── notebooks │ │ │ └── grove_pir.ipynb │ │ └── src │ │ │ └── grove_pir.c │ ├── grove_potentiometer │ │ ├── include │ │ │ └── grove_potentiometer.h │ │ ├── notebooks │ │ │ └── grove_potentiometer.ipynb │ │ └── src │ │ │ └── grove_potentiometer.c │ ├── grove_relay │ │ ├── include │ │ │ └── grove_relay.h │ │ ├── notebooks │ │ │ └── grove_relay.ipynb │ │ └── src │ │ │ └── grove_relay.c │ ├── grove_servo │ │ ├── include │ │ │ └── grove_servo.h │ │ ├── notebooks │ │ │ └── grove_servo.ipynb │ │ └── src │ │ │ └── grove_servo.c │ ├── grove_temperature │ │ ├── include │ │ │ └── grove_temperature.h │ │ ├── notebooks │ │ │ └── grove_temperature.ipynb │ │ └── src │ │ │ └── grove_temperature.c │ ├── grove_usranger │ │ ├── include │ │ │ └── grove_usranger.h │ │ ├── notebooks │ │ │ └── grove_usranger.ipynb │ │ └── src │ │ │ └── grove_usranger.c │ ├── grove_water_level │ │ ├── include │ │ │ └── grove_water_level.h │ │ ├── notebooks │ │ │ └── grove_water_level.ipynb │ │ └── src │ │ │ └── grove_water_level.c │ └── grove_water_sensor │ │ ├── include │ │ └── grove_water_sensor.h │ │ ├── notebooks │ │ └── grove_water_sensor.ipynb │ │ └── src │ │ └── grove_water_sensor.c └── templates │ └── __init__.py └── setup.py /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Creating a new peripheral driver 2 | 3 | To develop a new peripheral driver we recommend the following flow: 4 | 5 | * Clone this repository to your PYNQ board 6 | * Install the repository in editable mode - `sudo pip3 install -e ...` 7 | * Run `pynq new-peripheral` and follow the prompt 8 | 9 | Once the prompt has been completed there will be a new driver in the 10 | `pynq_peripheral/modules` folder which you can add your code to. You can use 11 | the existing Jupyter environment to test your code and develop your notebooks. 12 | Once you have finished with the driver, copy your notebooks into the driver's 13 | `notebooks` folder and you are ready to commit and share your new peripheral 14 | driver. 15 | 16 | # Coding guidelines for new peripherals 17 | 18 | To keep some consistency across all of the PYNQ drivers and to make best use of 19 | the PYNQ microblaze subsystem we have created a set of guidelines to keep in 20 | mind when developing your driver. If you've used the `pynq new-peripheral` 21 | command to create the template a lot of these will have been done for you. 22 | 23 | ## General points 24 | 25 | *Driver Name* 26 | 27 | Your driver should be of the form `{interface}_{peripheral}`, all in lower-case 28 | and words separated by underscores. 29 | 30 | *Consistent APIs* 31 | 32 | All drivers should contain the following: 33 | 34 | * A typedef from a basic C type to the name of the driver - this is generally an integer. 35 | * All functions in a drivers API except for `_open` should take a driver object as the first parameter 36 | * A `_close` function with no arguments other than the driver object should be provided 37 | 38 | *Header and source files* 39 | 40 | The main API for your driver should be in a `${driver_name}.h` file in your 41 | driver's include directory. This file constitutes the API as exported to 42 | Python and should meet the following: 43 | 44 | * Be plain C 45 | * Contain an include guard 46 | * Include no other header files where possible 47 | * Contain the driver typedef and all function for your API 48 | * Have no functions that don't conform to the rest of this docuemnt. 49 | 50 | All other header files should go in `include` and all source files in `src`. 51 | Source files should compile as both C and C++ but do not need to conform to the 52 | API specification. 53 | 54 | *Argument and return types* 55 | 56 | All functions in your API should conform to the following restrictions 57 | 58 | * Return void or primitive types 59 | * Take primitive, typedefs to primitives or arrays to primitives as arguments 60 | 61 | In addition consider the following restrictions and semantics 62 | 63 | * All pointer types except void are passed on the stack and so should be limited in size 64 | * const pointers should be used where possible - in particular python strings can only be passed as const char pointers 65 | * const char pointers from a string will be NULL-terminated 66 | * void* should be used for any data larger than 50 bytes - buffers passed as void* pointers must be allocated with pynq.allocate 67 | * Non-const pointers will copy data back into the python object so only writeable python objects can be used 68 | 69 | *Error handling and debugging* 70 | 71 | * Use the `pyexception` function to signal error conditions. This will abort 72 | the current function and throw an exception in python. 73 | * Use `pyprintf` to print debug information while developing or under error 74 | conditions - your driver should not print anything in normal operation. 75 | 76 | *Notebooks* 77 | 78 | Your driver should include one or more notebooks in its `notebooks` folder 79 | which _fully document_ the API you have implemented. Notebooks should contain 80 | both code and explanatory text introducing your API. It is important that every 81 | function in your public API be exercised by your included notebooks. 82 | 83 | We would rather have a slightly less functional but fully documented API than a 84 | more complete but undocumented one. 85 | 86 | Notebooks must include examples of all of your functions in Python but may 87 | optionally include Microblaze C code showing common patterns that users may 88 | wish to implement in C to improve the performance or functionality of the 89 | peripheral. 90 | 91 | *Including 3rd party code* 92 | 93 | Any third-party code should be clearly label, ensured that it is released under 94 | a compatible license and references to the origin and license added to the 95 | THIRD\_PARTY.md file 96 | 97 | ## Grove-specific guidelines 98 | 99 | For grove peripherals there are a few additional points to consider given that 100 | they are often used together through and adapter or shield. 101 | 102 | * Include `grove_constants.h` in your API header - this is an exception to the 103 | no-include rule to make using your library easier. 104 | * Your `_open` function should take only a single `int grove_id` argument 105 | which can be passed to the functions in `grove_interfaces.h` to open 106 | devices. 107 | * I2C peripherals can have an `_open_at_address` function which takes 108 | `grove_id` and `i2c_address` arguments. This is not required and the default 109 | should be the address the grove peripheral is shipped with. 110 | * You should expect that multiple instances of your device are used at the same 111 | time. Any state that is maintained on a per-device instance should be kept in 112 | a static array of at least 4 entries. This will be created automatically if you 113 | specify device-specific data when generating the template. 114 | 115 | Copyright (C) 2021 Xilinx, Inc 116 | 117 | SPDX-License-Identifier: BSD-3-Clause -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, Xilinx 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include pynq_peripherals * 2 | -------------------------------------------------------------------------------- /images/pynq_hackathon_hw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/images/pynq_hackathon_hw.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app0_plant_monitoring_system/notebooks/images/dry_arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app0_plant_monitoring_system/notebooks/images/dry_arduino.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app1_room_control_system/notebooks/images/rcs_ctl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app1_room_control_system/notebooks/images/rcs_ctl.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app1_room_control_system/notebooks/images/room_clip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app1_room_control_system/notebooks/images/room_clip.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app1_room_control_system/notebooks/images/room_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app1_room_control_system/notebooks/images/room_control.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app2_led_strings/notebooks/images/IMG_2204.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app2_led_strings/notebooks/images/IMG_2204.jpg -------------------------------------------------------------------------------- /pynq_peripherals/apps/app3_voice_enabled_room_control_system/notebooks/data/check_internet.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app3_voice_enabled_room_control_system/notebooks/data/check_internet.mp3 -------------------------------------------------------------------------------- /pynq_peripherals/apps/app3_voice_enabled_room_control_system/notebooks/data/room.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app3_voice_enabled_room_control_system/notebooks/data/room.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app4_automatic_door_control_and_motion_logger/notebooks/images/door_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app4_automatic_door_control_and_motion_logger/notebooks/images/door_control.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app5_pynq_car/notebooks/images/BlackLight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app5_pynq_car/notebooks/images/BlackLight.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app5_pynq_car/notebooks/images/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app5_pynq_car/notebooks/images/map.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app5_pynq_car/notebooks/images/motor_system.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app5_pynq_car/notebooks/images/motor_system.png -------------------------------------------------------------------------------- /pynq_peripherals/apps/app5_pynq_car/notebooks/images/pynq_car.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app5_pynq_car/notebooks/images/pynq_car.jpg -------------------------------------------------------------------------------- /pynq_peripherals/apps/app5_pynq_car/notebooks/images/sensor_connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xilinx/PYNQ_Peripherals/1ecb729bb0e744232ec389d88d097e1ec35aceb1/pynq_peripherals/apps/app5_pynq_car/notebooks/images/sensor_connection.png -------------------------------------------------------------------------------- /pynq_peripherals/cli.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Xilinx, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # 3. Neither the name of the copyright holder nor the names of its 15 | # contributors may be used to endorse or promote products derived from 16 | # this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | # OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | import argparse 31 | import os 32 | import shutil 33 | from .templates import TEMPLATES 34 | from simple_term_menu import TerminalMenu 35 | 36 | THIS_DIR = os.path.dirname(os.path.realpath(__file__)) 37 | DEFAULT_DIR = os.path.join(THIS_DIR, "modules") 38 | 39 | def _template_option_parser(): 40 | parser = argparse.ArgumentParser(description="Create new PYNQ peripheral") 41 | parser.add_argument("-f", "--force", help="Replace existing peripheral if present", 42 | action="store_true") 43 | parser.add_argument("-d", "--directory", help="Directory to create the new peripheral", 44 | default=DEFAULT_DIR) 45 | return parser 46 | 47 | def main(): 48 | parser = _template_option_parser() 49 | args = parser.parse_args() 50 | peripheral_name = input("Name for peripheral: ") 51 | peripheral_dir = os.path.join(args.directory, peripheral_name) 52 | if os.path.exists(peripheral_dir): 53 | if args.force: 54 | shutil.rmtree(peripheral_dir) 55 | else: 56 | raise RuntimeError("Peripheral already exists") 57 | template_index = TerminalMenu([t.name for t in TEMPLATES]).show() 58 | TEMPLATES[template_index].run(peripheral_name, peripheral_dir) 59 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/analog/include/analog.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | 38 | typedef py_int analog; 39 | 40 | // Device lifetime functions 41 | /* Open a device providing an anlog signal to the System Monitor of 42 | * the Zynq chip 43 | * 44 | * Parameters 45 | * ---------- 46 | * pin_id: int 47 | * Valid port ids for this device: 48 | * ARDUINO_SEEED_A0, ARDUINO_SEEED_A1, ARDUINO_SEEED_A2, ARDUINO_SEEED_A3 49 | * 50 | * Returns 51 | * ------- 52 | * analog 53 | * The device object if successful 54 | * -ENXIO no such device (raises exception) 55 | * 56 | */ 57 | analog analog_open_xadc(int pin_id); 58 | 59 | /* Open a Grove ADC module 60 | * 61 | * Parameters 62 | * ---------- 63 | * adc: int 64 | * Valid port ids for this device: 65 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 66 | * 67 | * Returns 68 | * ------- 69 | * analog 70 | * The device object if successful 71 | * -EIO device not present (raises exception) 72 | * 73 | */ 74 | analog analog_open_grove_adc(int adc); 75 | 76 | /* Release the connected analog source by closing the device 77 | * 78 | * Parameters 79 | * ---------- 80 | * None 81 | * 82 | * Returns 83 | * ------- 84 | * None 85 | * 86 | */ 87 | void analog_close(analog dev_id); 88 | 89 | // Device functions 90 | /* Read the analog signal and return voltage 91 | * 92 | * Parameters 93 | * ---------- 94 | * None 95 | * 96 | * Returns 97 | * ------- 98 | * float: 99 | * Voltage value 100 | * NAN general operation error (raises exception) 101 | * 102 | */ 103 | py_float analog_get_voltage(analog dev_id); 104 | 105 | /* Read the analog signal and return a 12-bit integer raw value 106 | * 107 | * Parameters 108 | * ---------- 109 | * None 110 | * 111 | * Returns 112 | * ------- 113 | * integer: 114 | * A 12-bit value from Grove ADC, 16-bit value from 115 | * System Monittor if successful 116 | * -EIO otherwise to raise exception 117 | */ 118 | py_int analog_get_raw(analog dev_id); 119 | 120 | /* Read the reference voltage 121 | * 122 | * Parameters 123 | * ---------- 124 | * None 125 | * 126 | * Returns 127 | * ------- 128 | * float: 129 | * 3.1V if Grove ADC, 3.3V if System Monitor 130 | * NAN general operation error (raises exception) 131 | * 132 | */ 133 | py_float analog_get_reference(analog dev_id); 134 | 135 | /* Get the maximum value that the selected device can return 136 | * 137 | * Parameters 138 | * ---------- 139 | * None 140 | * 141 | * Returns 142 | * ------- 143 | * A 12-bit or 16-bit integer value 144 | * -PY_INT_ERROR otherwise to raise exception 145 | */ 146 | py_int analog_get_max(analog dev_id); 147 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/analog/src/analog.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | 35 | #ifdef XPAR_SYSMON_0_DEVICE_ID 36 | #include 37 | static XSysMon SysMonInst; 38 | static XSysMon_Config *SysMonConfigPtr; 39 | static XSysMon *SysMonInstPtr = &SysMonInst; 40 | static int sysmon_init = 0; 41 | #endif 42 | 43 | 44 | #include 45 | #include 46 | 47 | #define XADC_TYPE 0l 48 | #define GROVE_ADC_TYPE (1l << 24) 49 | #define TYPE_MASK 0xF000000 50 | 51 | analog analog_open_xadc(int pin_id) { 52 | #ifdef XPAR_SYSMON_0_DEVICE_ID 53 | if (!sysmon_init) { 54 | SysMonConfigPtr = XSysMon_LookupConfig(XPAR_SYSMON_0_DEVICE_ID); 55 | XSysMon_CfgInitialize(SysMonInstPtr, SysMonConfigPtr, 56 | SysMonConfigPtr->BaseAddress); 57 | XSysMon_GetStatus(SysMonInstPtr); 58 | sysmon_init = 1; 59 | } 60 | return pin_id; 61 | #else 62 | return -ENXIO; 63 | #endif 64 | } 65 | 66 | analog analog_open_grove_adc(grove_adc adc) { 67 | return GROVE_ADC_TYPE | adc; 68 | } 69 | 70 | void analog_close(analog dev_id) { 71 | 72 | } 73 | 74 | py_float analog_get_voltage(analog dev_id) { 75 | return analog_get_raw(dev_id) * analog_get_reference(dev_id) 76 | / analog_get_max(dev_id); 77 | } 78 | 79 | py_int analog_get_raw(analog dev_id) { 80 | switch (dev_id & TYPE_MASK) { 81 | case XADC_TYPE: 82 | #ifdef XPAR_SYSMON_0_DEVICE_ID 83 | while ((XSysMon_GetStatus(SysMonInstPtr) & 84 | XSM_SR_EOS_MASK) != XSM_SR_EOS_MASK); 85 | return XSysMon_GetAdcData(SysMonInstPtr, XSM_CH_AUX_MIN+dev_id); 86 | #else 87 | return -ENXIO; 88 | #endif 89 | 90 | case GROVE_ADC_TYPE: 91 | return grove_adc_read_raw(dev_id ^ GROVE_ADC_TYPE); 92 | } 93 | return PY_SUCCESS; 94 | } 95 | 96 | py_float analog_get_reference(analog dev_id) { 97 | switch (dev_id & TYPE_MASK) { 98 | case XADC_TYPE: 99 | return 3.3f; 100 | case GROVE_ADC_TYPE: 101 | return 3.1f; 102 | } 103 | return PY_FLOAT_ERROR; 104 | } 105 | 106 | py_int analog_get_max(analog dev_id) { 107 | switch (dev_id & TYPE_MASK) { 108 | case XADC_TYPE: 109 | return 65536; 110 | case GROVE_ADC_TYPE: 111 | return 4096/2; // Voltage divider 112 | } 113 | return -ENXIO; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/geared_motor/include/geared_motor.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Servo class 41 | * 42 | * Available Methods: 43 | * open, close 44 | * set_speed, forward, backward 45 | * 46 | */ 47 | typedef py_int geared_motor; 48 | 49 | // Device lifetime functions 50 | /* Open a motor device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4 57 | * 58 | * Returns 59 | * ------- 60 | * geared_motor 61 | * The device object 62 | * 63 | */ 64 | geared_motor geared_motor_open(int grove_id); 65 | 66 | /* Release the motor by closing the device 67 | * 68 | * Parameters 69 | * ---------- 70 | * None 71 | * 72 | * Returns 73 | * ------- 74 | * None 75 | * 76 | */ 77 | void geared_motor_close(geared_motor p); 78 | 79 | // Device functions 80 | /* Set the speed of the motor 81 | * 82 | * Parameters 83 | * ---------- 84 | * value: int 85 | * The speed percentage of the motor from 0 - 100 86 | * 87 | * Returns 88 | * ------- 89 | * None 90 | * 91 | */ 92 | py_void geared_motor_set_speed(geared_motor p, int value); 93 | 94 | 95 | // Device functions 96 | /* Set the driection of the motor to forward 97 | * 98 | * Parameters 99 | * ---------- 100 | * None 101 | * 102 | * Returns 103 | * ------- 104 | * None 105 | * 106 | */ 107 | void geared_motor_forward(geared_motor p); 108 | 109 | // Device functions 110 | /* Set the driection of the motor to backward 111 | * 112 | * Parameters 113 | * ---------- 114 | * None 115 | * 116 | * Returns 117 | * ------- 118 | * None 119 | * 120 | */ 121 | void geared_motor_backward(geared_motor p); -------------------------------------------------------------------------------- /pynq_peripherals/modules/geared_motor/src/geared_motor.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #define DEVICE_MAX 4 38 | #define PERIOD 2000000 39 | #define DUTY_MAX 1999999 40 | #define DUTY_MIN 20000 41 | 42 | struct info { 43 | timer motor_pin; 44 | gpio dir_pin; 45 | int count; 46 | }; 47 | 48 | static struct info info[DEVICE_MAX]; 49 | 50 | /* 51 | * Documentation for public functions is provided as part of the external 52 | * public header file. 53 | * Documentation for static/private functions is provided above each 54 | * function in this file. 55 | */ 56 | 57 | /* Get next instance space 58 | * 59 | * Parameters 60 | * ---------- 61 | * None 62 | * 63 | * Return 64 | * ------ 65 | * int 66 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 67 | * 68 | */ 69 | static int next_index() { 70 | for (int i = 0; i < DEVICE_MAX; ++i) { 71 | if (info[i].count == 0) return i; 72 | } 73 | return -ENOMEM; 74 | } 75 | geared_motor geared_motor_open(int grove_id) { 76 | geared_motor dev_id = next_index(); 77 | if (dev_id >= 0) { 78 | info[dev_id].count++; 79 | info[dev_id].motor_pin = timer_open_grove_b(grove_id); 80 | info[dev_id].dir_pin = gpio_open_grove_a(grove_id); 81 | timer_pwm_generate(info[dev_id].motor_pin, PERIOD, 0); 82 | gpio_set_direction(info[dev_id].dir_pin, GPIO_OUT); 83 | gpio_write(info[dev_id].dir_pin, 1); 84 | } 85 | return dev_id; 86 | } 87 | 88 | void geared_motor_close(geared_motor p) { 89 | if (--info[p].count != 0) return; 90 | timer motor_pin = info[p].motor_pin; 91 | gpio dir_pin = info[p].dir_pin; 92 | timer_pwm_stop(motor_pin); 93 | timer_close(motor_pin); 94 | gpio_close(dir_pin); 95 | } 96 | 97 | py_void geared_motor_set_speed(geared_motor p, int value) { 98 | timer pin = info[p].motor_pin; 99 | if (value >= 0 && value <= 100) { 100 | int duty_cycle = DUTY_MAX * value / 100; 101 | timer_pwm_generate(pin, PERIOD, duty_cycle); 102 | return PY_SUCCESS; 103 | } else { 104 | return -EPERM; 105 | } 106 | } 107 | 108 | void geared_motor_forward(geared_motor p) { 109 | gpio dir_pin = info[p].dir_pin; 110 | gpio_write(dir_pin, 1); 111 | } 112 | 113 | void geared_motor_backward(geared_motor p) { 114 | gpio dir_pin = info[p].dir_pin; 115 | gpio_write(dir_pin, 0); 116 | } 117 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_adc/include/grove_adc.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* ADC class 42 | * 43 | * Available Methods: 44 | * open, open_at_address, close, read_raw, read 45 | * 46 | */ 47 | typedef py_int grove_adc; 48 | 49 | // Device lifetime functions 50 | /* Open an ADC module connected to the specified port with the default 51 | * I2C address 52 | * 53 | * Parameters 54 | * ---------- 55 | * grove_id: int 56 | * Valid port ids for this device: 57 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 58 | * 59 | * Returns 60 | * ------- 61 | * grove_adc 62 | * The device object if successful 63 | * -EIO device not present (raises exception) 64 | * 65 | */ 66 | grove_adc grove_adc_open(int grove_id); 67 | 68 | /* Open an ADC module connected to the specified port and a non-default 69 | * I2C address 70 | * 71 | * Unique I2C address is needed when two modules of same type are connected 72 | * to the same I2C channel. The two modules should have unique I2C 73 | * address 74 | * 75 | * Parameters 76 | * ---------- 77 | * grove_id: int 78 | * Valid port ids for this device: 79 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 80 | * address: integer 81 | * 82 | * Returns 83 | * ------- 84 | * grove_adc 85 | * The device object if successful 86 | * -EIO device not present (raises exception) 87 | * 88 | */ 89 | grove_adc grove_adc_open_at_address(int grove_id, int address); 90 | 91 | /* Release the ADC by closing the device 92 | * 93 | * Parameters 94 | * ---------- 95 | * None 96 | * 97 | * Returns 98 | * ------- 99 | * None 100 | * 101 | */ 102 | void grove_adc_close(grove_adc adc); 103 | 104 | // Device functions 105 | /* Read the ADC and return a 12-bit integer raw value 106 | * 107 | * Parameters 108 | * ---------- 109 | * None 110 | * 111 | * Returns 112 | * ------- 113 | * A 12-bit integer value if successful 114 | * -EIO otherwise to raise exception 115 | */ 116 | py_int grove_adc_read_raw(grove_adc adc); 117 | 118 | /* Read the ADC and return voltage 119 | * 120 | * Parameters 121 | * ---------- 122 | * None 123 | * 124 | * Returns 125 | * ------- 126 | * float: 127 | * Voltage value in degree Celsius 128 | * NAN general operation error (raises exception) 129 | * 130 | */ 131 | py_float grove_adc_read(grove_adc adc); -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_adc/src/grove_adc.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | // VRef = Va measured on the board 40 | #define V_REF 3.14 41 | 42 | // ADC Registers 43 | #define REG_ADDR_RESULT 0x00 44 | #define REG_ADDR_CONFIG 0x02 45 | 46 | /* 47 | * Documentation for public functions is provided as part of the external 48 | * public header file. 49 | * Documentation for static/private functions is provided above each 50 | * function in this file. 51 | */ 52 | 53 | /* Read converted result 54 | * 55 | * Parameters 56 | * ---------- 57 | * 58 | * address: u8 59 | * Device address. 60 | * reg: u8 61 | * Register address to read. 62 | * 63 | * Return 64 | * ------ 65 | * int 66 | * The read data. Return -1 (EIO) if errors on read. 67 | * 68 | */ 69 | static int read_adc(i2c device, u8 address, u8 reg){ 70 | u8 data_buffer[2]; 71 | u32 sample; 72 | u8 num_bytes; 73 | 74 | data_buffer[0] = reg; // Set the address pointer register 75 | if(i2c_write(device, address, data_buffer, 1) != 1) return -EIO; 76 | 77 | if(i2c_read(device, address, data_buffer, 2) != 2) return -EIO; 78 | sample = ((data_buffer[0]&0x0f) << 8) | data_buffer[1]; 79 | return sample; 80 | } 81 | 82 | /* Write command to a register 83 | * Maximum of 2 data bytes can be written in one transaction 84 | * 85 | * Parameters 86 | * ---------- 87 | * 88 | * address: u8 89 | * Device address. 90 | * reg: u8 91 | * Register address to read. 92 | * data: u32 93 | * Data to be written. 94 | * bytes: u8 95 | * Number of bytes to be written. 96 | * 97 | * Return 98 | * ------ 99 | * int 100 | * The number of bytes written. Return -1 (EIO) if errors on write. 101 | * 102 | */ 103 | static int write_adc(i2c device, u8 address, u8 reg, u32 data, u8 bytes){ 104 | u8 data_buffer[3]; 105 | data_buffer[0] = reg; 106 | if(bytes ==2){ 107 | data_buffer[1] = (data >> 8) & 0x0f; // Bits 11:8 108 | data_buffer[2] = data & 0xff; // Bits 7:0 109 | }else{ 110 | data_buffer[1] = data & 0xff; // Bits 7:0 111 | } 112 | if(i2c_write(device, address, data_buffer, bytes+1) != (bytes+1)) return -EIO; 113 | else return (bytes+1); 114 | 115 | } 116 | 117 | #define I2C_ADDRESS 0x50 118 | #define DEVICE_MAX 4 119 | 120 | struct info { 121 | i2c i2c_dev; 122 | unsigned char address; 123 | int count; 124 | }; 125 | 126 | static struct info info[DEVICE_MAX]; 127 | 128 | /* Get next instance space 129 | * 130 | * Parameters 131 | * ---------- 132 | * None 133 | * 134 | * Return 135 | * ------ 136 | * int 137 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 138 | * 139 | */ 140 | static int next_index() { 141 | for (int i = 0; i < DEVICE_MAX; ++i) { 142 | if (info[i].count == 0) return i; 143 | } 144 | return -ENOMEM; 145 | } 146 | 147 | grove_adc grove_adc_open(int grove_id) { 148 | return grove_adc_open_at_address(grove_id, I2C_ADDRESS); 149 | } 150 | 151 | grove_adc grove_adc_open_at_address(int grove_id, int address) { 152 | grove_adc dev_id = next_index(); 153 | if (dev_id >=0 ) { 154 | info[dev_id].count++; 155 | info[dev_id].i2c_dev = i2c_open_grove(grove_id); 156 | info[dev_id].address = address; 157 | if(write_adc(info[dev_id].i2c_dev,info[dev_id].address, REG_ADDR_CONFIG,0x20,1) == -EIO){ 158 | info[dev_id].count--; 159 | i2c_close(info[dev_id].i2c_dev); 160 | return -EIO; 161 | } 162 | } 163 | return dev_id; 164 | } 165 | 166 | void grove_adc_close(grove_adc adc) { 167 | if (--info[adc].count != 0) return; 168 | i2c i2c_dev = info[adc].i2c_dev; 169 | i2c_close(i2c_dev); 170 | } 171 | 172 | py_int grove_adc_read_raw(grove_adc adc) { 173 | return read_adc(info[adc].i2c_dev, info[adc].address, REG_ADDR_RESULT); 174 | } 175 | 176 | py_float grove_adc_read(grove_adc adc) { 177 | int raw = grove_adc_read_raw(adc); 178 | if (raw == -1) return PY_FLOAT_ERROR; 179 | return (raw * V_REF) * 2 / 4096; // Voltage divider 180 | } -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_barometer/include/grove_barometer_hw.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS py_intERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | // Register address definitions 36 | #define BPS_REG_RESET 0x0C /**< Reset register */ 37 | #define BPS_REG_PRSCFG 0x06 /**< Pressure configuration register */ 38 | #define BPS_REG_TMPCFG 0x07 /**< Temperature configuration register */ 39 | #define BPS_REG_MEASCFG 0x08 /**< Sensor Operating Mode and Status register */ 40 | #define BPS_REG_CFGREG 0x09 /**< py_interrupt and FIFO configuration register */ 41 | #define BPS_REG_TMP_BASE 0x03 /**< Temperature Data base register */ 42 | #define BPS_REG_PRS_BASE 0x00 /**< Pressure Data base register */ 43 | #define BPS_REG_TMPSRC 0x28 /**< Coefficient Source register */ 44 | #define BPS_REG_ID 0x0D /**< Product and Revision ID register */ 45 | #define BPS_REG_COEFF_BASE 0x10 /**< Calibration Coefficients register */ 46 | #define BPS_REG_FIFO_STS 0x0B /**< FIFO status Register */ 47 | 48 | #define BPS_COEFFICIENT_COUNT 9 /**< Number of coefficients */ 49 | #define BPS_COEFFICIENT_SIZE 18 /**< Size of all of the coefficients in bytes except c00 and c010 */ 50 | 51 | #define BPS_CMD_RESET 0x89 /**< Reset command */ 52 | #define BPS_CMD_T_SHIFT 0x08 /**< Temperature and pressure result shift command */ 53 | #define BPS_CMD_P_SHIFT 0x04 /**< Temperature and pressure result shift command */ 54 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_buzzer/include/grove_buzzer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* Buzzer class 42 | * 43 | * Available Methods: 44 | * open, close, play_tone, play_note, demo 45 | * 46 | */ 47 | typedef py_int grove_buzzer; 48 | 49 | // Device lifetime functions 50 | /* Open a Buzzer device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_buzzer 63 | * The device object if successful 64 | * -ENOMEM otherwise 65 | * 66 | */ 67 | grove_buzzer grove_buzzer_open(int grove_id); 68 | 69 | /* Release the Buzzer by closing the device 70 | * 71 | * Parameters 72 | * ---------- 73 | * None 74 | * 75 | * Returns 76 | * ------- 77 | * None 78 | * 79 | */ 80 | void grove_buzzer_close(grove_buzzer buzzer); 81 | 82 | // Device functions 83 | /* Play a specified tone for a period of time 84 | * 85 | * Parameters 86 | * ---------- 87 | * tone: int 88 | * The frequency of tone in Hz 89 | * duration: int 90 | * Duration in millisecond 91 | * 92 | * Returns 93 | * ------- 94 | * None 95 | * 96 | */ 97 | py_void grove_buzzer_play_tone(grove_buzzer buzzer, int tone, int duration); 98 | 99 | /* Play the tone corresponding to the note for a period of time 100 | * 101 | * The parameter note specifies the tone for playing. The available notes 102 | * are c, d, e, f, g, a, b, C, D, representing the pitch from the middle C 103 | * to the high D. 104 | * 105 | * Parameters 106 | * ---------- 107 | * note: const char* 108 | * Note of a certain tone 109 | * duration: int 110 | * Duration in millisecond 111 | * 112 | * Returns 113 | * ------- 114 | * None 115 | * 116 | */ 117 | py_void grove_buzzer_play_note(grove_buzzer buzzer, const char* note, int duration); 118 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_buzzer/src/grove_buzzer.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define DEVICE_MAX 4 39 | 40 | struct info { 41 | gpio pin; 42 | int count; 43 | }; 44 | 45 | static struct info info[DEVICE_MAX]; 46 | 47 | /* 48 | * Documentation for public functions is provided as part of the external 49 | * public header file. 50 | * Documentation for static/private functions is provided above each 51 | * function in this file. 52 | */ 53 | 54 | /* Get next instance space 55 | * 56 | * Parameters 57 | * ---------- 58 | * None 59 | * 60 | * Return 61 | * ------ 62 | * int 63 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 64 | * 65 | */ 66 | static int next_index() { 67 | for (int i = 0; i < DEVICE_MAX; ++i) { 68 | if (info[i].count == 0) return i; 69 | } 70 | return -ENOMEM; 71 | } 72 | 73 | grove_buzzer grove_buzzer_open(int grove_id) { 74 | grove_buzzer dev_id = next_index(); 75 | if (dev_id >= 0) { 76 | info[dev_id].count++; 77 | info[dev_id].pin = gpio_open_grove(grove_id); 78 | gpio_set_direction(info[dev_id].pin, GPIO_OUT); 79 | } 80 | return dev_id; 81 | } 82 | 83 | void grove_buzzer_close(grove_buzzer buzzer) { 84 | if (--info[buzzer].count != 0) return; 85 | gpio pin = info[buzzer].pin; 86 | gpio_close(pin); 87 | } 88 | 89 | py_void grove_buzzer_play_tone(grove_buzzer buzzer, int tone, int duration) { 90 | gpio pin = info[buzzer].pin; 91 | int period = 1000000/tone; 92 | for (long i = 0; i < duration * 1000L; i += period) { 93 | gpio_write(pin, 1); 94 | delay_us(period/2); 95 | gpio_write(pin, 0); 96 | delay_us(period/2); 97 | } 98 | return PY_SUCCESS; 99 | } 100 | 101 | py_void grove_buzzer_play_note(grove_buzzer buzzer, const char* note, int duration) { 102 | char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D' }; 103 | int tones[] = {262, 294, 330, 349, 392, 440, 494, 523, 587}; 104 | 105 | 106 | for (int i = 0; i < 8; i++) { 107 | if (names[i] == note[0]) { 108 | grove_buzzer_play_tone(buzzer, tones[i], duration); 109 | } 110 | } 111 | return PY_SUCCESS; 112 | } 113 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_capacitive_soil_moisture/include/grove_capacitive_soil_moisture.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Device typedef 41 | 42 | /* Capacitive_soil_moisture class 43 | * 44 | * Available Methods: 45 | * open, close, get_moisture, calibrate_dry, calibrate_wet 46 | * 47 | */ 48 | typedef py_int grove_capacitive_soil_moisture; 49 | 50 | // Device lifetime functions 51 | /* Open a capacitive soil moisture module connected directly to one of Arduino analog ports 52 | * or via a Grove ADC module (at default address) to an I2C port 53 | * 54 | * Parameters 55 | * ---------- 56 | * grove_id: int 57 | * Valid port ids for this device: 58 | * ARDUINO_SEEED_A0, ARDUINO_SEEED_A1, ARDUINO_SEEED_A2, ARDUINO_SEEED_A3 59 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C (via I2C ADC) 60 | * 61 | * Returns 62 | * ------- 63 | * grove_capacitive_soil_moisture 64 | * The device object if successful 65 | * -EIO device not present (raises exception) 66 | * -ENOMEM memory allocation error (raises exception) 67 | * 68 | */ 69 | grove_capacitive_soil_moisture grove_capacitive_soil_moisture_open(int grove_id); 70 | 71 | /* Open a capacitive soil moisture module connected to Grove_ADC module 72 | * 73 | * Parameters 74 | * ---------- 75 | * grove_id: int 76 | * Valid port ids for this device: 77 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 78 | * address: int 79 | * I2C address of the ADC 80 | * 81 | * Returns 82 | * ------- 83 | * grove_capacitive_soil_moisture 84 | * The device object if successful 85 | * -EIO device not present (raises exception) 86 | * -ENOMEM memory allocation error (raises exception) 87 | * 88 | */ 89 | grove_capacitive_soil_moisture grove_capacitive_soil_moisture_open_at_address(int grove_id, int address); 90 | 91 | /* Release the capacitive soil moisture module by closing the device 92 | * 93 | * Parameters 94 | * ---------- 95 | * grove_id : int 96 | * The opened device object 97 | * 98 | * Returns 99 | * ------- 100 | * None 101 | * 102 | */ 103 | void grove_capacitive_soil_moisture_close(grove_capacitive_soil_moisture moisture); 104 | 105 | // Device functions 106 | /* Read the connected device and return the soil moisture in percentage 107 | * 108 | * Parameters 109 | * ---------- 110 | * None 111 | * 112 | * Returns 113 | * ------- 114 | * float: 115 | * soil moisture in percentage 116 | * NAN general operation error (raises exception) 117 | * 118 | */ 119 | py_float grove_capacitive_soil_moisture_get_moisture(grove_capacitive_soil_moisture moisture); 120 | 121 | /* Calibrate the device in dry air (record the state of 0% humidity) 122 | * 123 | * Parameters 124 | * ---------- 125 | * None 126 | * 127 | * Returns 128 | * ------- 129 | * None 130 | */ 131 | void grove_capacitive_soil_moisture_calibrate_dry(grove_capacitive_soil_moisture moisture); 132 | 133 | /* Calibrate the device in water (record the state of 100% humidity) 134 | * 135 | * Parameters 136 | * ---------- 137 | * None 138 | * 139 | * Returns 140 | * ------- 141 | * None 142 | */ 143 | void grove_capacitive_soil_moisture_calibrate_wet(grove_capacitive_soil_moisture moisture); -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_capacitive_soil_moisture/src/grove_capacitive_soil_moisture.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include "grove_constants.h" 37 | 38 | #define DEVICE_MAX 4 39 | 40 | struct info { 41 | analog pin; 42 | int count; 43 | }; 44 | 45 | static struct info info[DEVICE_MAX]; 46 | 47 | float voltage_dry = 61.66; 48 | float voltage_wet = 72.47; 49 | 50 | /* 51 | * Documentation for public functions is provided as part of the external 52 | * public header file. 53 | * Documentation for static/private functions is provided above each 54 | * function in this file. 55 | */ 56 | 57 | /* Get next instance space 58 | * 59 | * Parameters 60 | * ---------- 61 | * None 62 | * 63 | * Return 64 | * ------ 65 | * int 66 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 67 | * 68 | */ 69 | static int next_index() { 70 | for (int i = 0; i < DEVICE_MAX; ++i) { 71 | if (info[i].count == 0) return i; 72 | } 73 | return -ENOMEM; 74 | } 75 | 76 | static grove_capacitive_soil_moisture grove_capacitive_soil_moisture_open_analog(analog pin) { 77 | grove_capacitive_soil_moisture dev_id = next_index(); 78 | if (dev_id >= 0) { 79 | info[dev_id].count++; 80 | info[dev_id].pin = pin; 81 | } 82 | return dev_id; 83 | } 84 | 85 | grove_capacitive_soil_moisture grove_capacitive_soil_moisture_open(int grove_id) { 86 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) 87 | return grove_capacitive_soil_moisture_open_analog(analog_open_grove(grove_id)); 88 | else 89 | return grove_capacitive_soil_moisture_open_analog(analog_open_grove_adc(grove_adc_open(grove_id))); 90 | } 91 | 92 | grove_capacitive_soil_moisture grove_capacitive_soil_moisture_open_at_address(int grove_id, int address) { 93 | return grove_capacitive_soil_moisture_open_analog(analog_open_grove_adc(grove_adc_open_at_address(grove_id, address))); 94 | } 95 | 96 | void grove_capacitive_soil_moisture_close(grove_capacitive_soil_moisture moisture) { 97 | if (--info[moisture].count != 0) return; 98 | analog pin = info[moisture].pin; 99 | analog_close(pin); 100 | } 101 | 102 | py_float grove_capacitive_soil_moisture_get_moisture(grove_capacitive_soil_moisture moisture) { 103 | analog pin = info[moisture].pin; 104 | float voltage = 100 - (float)analog_get_voltage(pin) * 100.0 / (float)analog_get_reference(pin); 105 | float humidity = 100/(voltage_wet - voltage_dry)*(voltage - voltage_dry); 106 | humidity = (humidity < 0) ? 0 : humidity; 107 | humidity = (humidity > 100) ? 100 : humidity; 108 | return humidity; 109 | } 110 | 111 | void grove_capacitive_soil_moisture_calibrate_dry(grove_capacitive_soil_moisture moisture) { 112 | analog pin = info[moisture].pin; 113 | voltage_dry = 100 - (float)analog_get_voltage(pin) * 100.0 / (float)analog_get_reference(pin); 114 | } 115 | 116 | void grove_capacitive_soil_moisture_calibrate_wet(grove_capacitive_soil_moisture moisture) { 117 | analog pin = info[moisture].pin; 118 | voltage_wet = 100 - (float)analog_get_voltage(pin) * 100.0 / (float)analog_get_reference(pin); 119 | } -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_envsensor/include/grove_envsensor.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS py_intERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | 38 | // Device typedef 39 | /* grove_envsensor class 40 | * 41 | * Available Methods: 42 | * open, open_at_address,close,init, 43 | * reg_write, read_data, read_temperature, read_pressure 44 | * read_humidity 45 | * 46 | */ 47 | typedef int grove_envsensor; 48 | 49 | // Device lifetime functions 50 | /* Open a grove environment sensor device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_water 63 | * The device object 64 | * -ENOMEM if memory error 65 | * 66 | */ 67 | grove_envsensor grove_envsensor_open(int grove_id); 68 | 69 | /* Open a grove environment sensor device at a specified I2C address 70 | * 71 | * Parameters 72 | * ---------- 73 | * grove_id: int 74 | * Valid port ids for this device: 75 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 76 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 77 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 78 | * address: int 79 | * i2c address of the grove environemnt sensor 80 | * 81 | * Returns 82 | * ------- 83 | * grove_water 84 | * The device object 85 | * -ENOMEM if memory error 86 | * 87 | */ 88 | grove_envsensor grove_envsensor_open_at_address(int grove_id, int address); 89 | 90 | /* Release the grove barometer sensor by closing the device 91 | * 92 | * Parameters 93 | * ---------- 94 | * None 95 | * 96 | * Returns 97 | * ------- 98 | * None 99 | * 100 | */ 101 | void grove_envsensor_close(grove_envsensor p); 102 | 103 | // Device functions 104 | 105 | /* Write register at given address for environement sensor 106 | * 107 | * Parameters 108 | * ---------- 109 | * addr: char 110 | * address if register to write 111 | * val: char 112 | * value to write to regiter 113 | * 114 | * Returns 115 | * ------- 116 | * None 117 | * 118 | */ 119 | py_int grove_envsensor_reg_write(grove_envsensor p, unsigned char addr, unsigned char val); 120 | 121 | /* Read all raw data from the sensor 122 | * 123 | * Parameters 124 | * ---------- 125 | * None 126 | * 127 | * Returns 128 | * ------- 129 | * 0 = All data read into internal buffers 130 | * 1 = Failed to setup sensor 131 | * 2 = Failed to set sensor mode 132 | * 3 = Failed to read sensor data 133 | * 134 | */ 135 | py_int grove_envsensor_read_data(grove_envsensor p); 136 | 137 | /* Read temperature value 138 | * 139 | * Parameters 140 | * ---------- 141 | * None 142 | * 143 | * Returns 144 | * ------- 145 | * temperature value: float 146 | * 147 | */ 148 | py_float grove_envsensor_read_temperature(grove_envsensor p); 149 | 150 | /* Read pressure value 151 | * 152 | * Parameters 153 | * ---------- 154 | * None 155 | * 156 | * Returns 157 | * ------- 158 | * pressure value: float 159 | * 160 | */ 161 | py_float grove_envsensor_read_pressure(grove_envsensor p); 162 | 163 | /* Read humidity value 164 | * 165 | * Parameters 166 | * ---------- 167 | * None 168 | * 169 | * Returns 170 | * ------- 171 | * humidity value: float 172 | * 173 | */ 174 | py_float grove_envsensor_read_humidity(grove_envsensor p); 175 | py_float grove_envsensor_read_gas(grove_envsensor p); 176 | 177 | /* Initilize grve environement sensor 178 | * 179 | * Parameters 180 | * ---------- 181 | * None 182 | * 183 | * Returns 184 | * ------- 185 | * 1 = Sensor init done 186 | * 0 = Sensor init failed 187 | * 188 | */ 189 | py_int grove_envsensor_init(grove_envsensor p); 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_gesture/include/grove_gesture.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | #include 35 | #include 36 | 37 | enum GESTURE_MAP { 38 | NONE, 39 | FORWORD, 40 | BACKWORD, 41 | RIGHT, 42 | LEFT, 43 | UP, 44 | DOWN, 45 | CLK_WISE, 46 | AN_CLK_WISE, 47 | WAVE 48 | }; 49 | 50 | typedef py_int grove_gesture; 51 | 52 | // Device lifetime functions 53 | 54 | /* Open a Gesture module connected to the specified port with the default 55 | * I2C address 56 | * 57 | * Parameters 58 | * ---------- 59 | * grove_id: int 60 | * Valid port ids for this device: 61 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 62 | * 63 | * Returns 64 | * ------- 65 | * grove_gesture 66 | * The device object if successful 67 | * -EIO device not present (raises exception) 68 | * 69 | */ 70 | grove_gesture grove_gesture_open(int grove_id); 71 | 72 | /* Open a Gesture module connected to the specified port and a non-default 73 | * I2C address 74 | * 75 | * Unique I2C address is needed when two modules of same type are connected 76 | * to the same I2C channel. The two modules should have unique I2C 77 | * address 78 | * 79 | * Parameters 80 | * ---------- 81 | * grove_id: int 82 | * Valid port ids for this device: 83 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 84 | * address: int 85 | * IC2 address of the device 86 | * 87 | * Returns 88 | * ------- 89 | * grove_adc 90 | * The device object if successful 91 | * -EIO device not present (raises exception) 92 | * 93 | */ 94 | grove_gesture grove_gesture_open_at_address(int grove_id, int address); 95 | 96 | /* Release the Gesture by closing the device 97 | * 98 | * Parameters 99 | * ---------- 100 | * None 101 | * 102 | * Returns 103 | * ------- 104 | * None 105 | * 106 | */ 107 | void grove_gesture_close(grove_gesture gesture); 108 | 109 | 110 | // Device functions 111 | 112 | /* Read the Gesture sensor and return gesture code 113 | * 114 | * Parameters 115 | * ---------- 116 | * None 117 | * 118 | * Returns 119 | * ------- 120 | * int: 121 | * NONE (0) 122 | * FORWORD (1) 123 | * BACKWORD (2) 124 | * RIGHT (3) 125 | * LEFT (4) 126 | * UP (5) 127 | * DOWN (6) 128 | * CLK_WISE (7) 129 | * AN_CLK_WISE (8) 130 | * WAVE (9) 131 | * 132 | */ 133 | py_int grove_gesture_gesture(grove_gesture gesture); 134 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_gesture/include/grove_gesture_hw.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | // REGISTER DESCRIPTION 34 | #define PAJ7620_ADDR_BASE 0x00 35 | #define PAJ7620_VAL(val, maskbit) ( val << maskbit ) 36 | 37 | // REGISTER BANK SELECT 38 | #define PAJ7620_REGITER_BANK_SEL (PAJ7620_ADDR_BASE + 0xEF) //W 39 | 40 | // DEVICE ID 41 | #define PAJ7620_ID 0x73 42 | 43 | // PAJ7620_REGITER_BANK_SEL 44 | #define PAJ7620_BANK0 PAJ7620_VAL(0,0) 45 | #define PAJ7620_BANK1 PAJ7620_VAL(1,0) 46 | 47 | #define GES_RIGHT_FLAG PAJ7620_VAL(1,0) 48 | #define GES_LEFT_FLAG PAJ7620_VAL(1,1) 49 | #define GES_UP_FLAG PAJ7620_VAL(1,2) 50 | #define GES_DOWN_FLAG PAJ7620_VAL(1,3) 51 | #define GES_FORWARD_FLAG PAJ7620_VAL(1,4) 52 | #define GES_BACKWARD_FLAG PAJ7620_VAL(1,5) 53 | #define GES_CLOCKWISE_FLAG PAJ7620_VAL(1,6) 54 | #define GES_COUNT_CLOCKWISE_FLAG PAJ7620_VAL(1,7) 55 | #define GES_WAVE_FLAG PAJ7620_VAL(1,0) 56 | #define GES_REACTION_TIME 500 57 | #define GES_ENTRY_TIME 800 58 | #define GES_QUIT_TIME 1000 59 | 60 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_imu/include/grove_imu_constants.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | enum GROVE_IMU { 36 | CLOCK_INTERNAL=0, 37 | CLOCK_PLL_XGYRO=1, 38 | CLOCK_PLL_YGRYO=2, 39 | CLOCK_PLL_ZGYRO=3, 40 | CLOCK_PLL_EXT32K=4, 41 | CLOCK_EXT19M=5, 42 | CLOCK_KEEP_RESET=7, 43 | GYRO_FS_250=0, 44 | GYRO_FS_500=1, 45 | GYRO_FS_1000=2, 46 | GYRO_FS_2000=3, 47 | ACCEL_FS_2=0, 48 | ACCEL_FS_4=1, 49 | ACCEL_FS_8=2, 50 | ACCEL_FS_16=3, 51 | SLEEP_DISABLED=0, 52 | SLEEP_ENABLED=1, 53 | }; 54 | 55 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_interfaces/include/grove_constants.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | 36 | enum GROVE_INTERFACE { 37 | PMOD_G1, 38 | PMOD_G2, 39 | PMOD_G3, 40 | PMOD_G4, 41 | GROVE1, 42 | GROVE2, 43 | ARDUINO_DIGILENT_UART, 44 | ARDUINO_DIGILENT_G1, 45 | ARDUINO_DIGILENT_G2, 46 | ARDUINO_DIGILENT_G3, 47 | ARDUINO_DIGILENT_G4, 48 | ARDUINO_DIGILENT_G5, 49 | ARDUINO_DIGILENT_G6, 50 | ARDUINO_DIGILENT_G7, 51 | ARDUINO_SEEED_UART, 52 | ARDUINO_SEEED_D2, 53 | ARDUINO_SEEED_D3, 54 | ARDUINO_SEEED_D4, 55 | ARDUINO_SEEED_D5, 56 | ARDUINO_SEEED_D6, 57 | ARDUINO_SEEED_D7, 58 | ARDUINO_SEEED_D8, 59 | ARDUINO_DIGILENT_A1, 60 | ARDUINO_DIGILENT_A2, 61 | ARDUINO_DIGILENT_A3, 62 | ARDUINO_DIGILENT_A4, 63 | ARDUINO_SEEED_A0, 64 | ARDUINO_SEEED_A1, 65 | ARDUINO_SEEED_A2, 66 | ARDUINO_SEEED_A3, 67 | ARDUINO_SEEED_I2C, 68 | ARDUINO_DIGILENT_I2C, 69 | }; 70 | 71 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_interfaces/include/grove_interfaces.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #define PYNQ_HAS_I2C 34 | #define PYNQ_HAS_GPIO 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifdef PYNQ_HAS_I2C 44 | i2c i2c_open_grove(int grove_id); 45 | #endif 46 | #ifdef PYNQ_HAS_UART 47 | uart uart_open_grove(int grove_id); 48 | #endif 49 | #ifdef PYNQ_HAS_GPIO 50 | gpio gpio_open_grove(int grove_id); 51 | gpio gpio_open_grove_a(int grove_id); 52 | gpio gpio_open_grove_b(int grove_id); 53 | #endif 54 | analog analog_open_grove(int grove_id); 55 | analog analog_open_grove_a(int grove_id); 56 | analog analog_open_grove_b(int grove_id); 57 | timer timer_open_grove(int grove_id); 58 | timer timer_open_grove_a(int grove_id); 59 | timer timer_open_grove_b(int grove_id); 60 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_interfaces/src/grove_interfaces.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include "grove_interfaces.h" 34 | #include "grove_constants.h" 35 | #include 36 | 37 | enum GROVE_MAX { 38 | GROVE_GENERAL_MAX = ARDUINO_SEEED_D8, 39 | GROVE_ANALOG_MAX = ARDUINO_SEEED_A3, 40 | GROVE_I2C_MAX = GROVE2, 41 | GROVE_UART_MAX = ARDUINO_SEEED_UART 42 | }; 43 | 44 | unsigned char digital_pins[][2] = { 45 | {0, 4}, // PMOD 46 | {1, 5}, 47 | {7, 3}, 48 | {6, 2}, 49 | {0, 1}, // GROVE 50 | {2, 3}, 51 | {0, 1}, // ARDUINO DIGILENT UART 52 | {2, 3}, // ARDUINO DIGILENT G* 53 | {3, 4}, 54 | {4, 5}, 55 | {6, 7}, 56 | {8, 9}, 57 | {10, 11}, 58 | {12, 13}, 59 | {0, 1}, // ARDUINO SEEED UART 60 | {2, 3}, // ARDUINO SEEED D* 61 | {3, 4}, 62 | {4, 5}, 63 | {5, 6}, 64 | {6, 7}, 65 | {7, 8}, 66 | {8, 9} 67 | }; 68 | 69 | unsigned char analog_pins[][2] = { 70 | {1, 9}, 71 | {6, 15}, 72 | {15, 5}, 73 | {5, 13}, 74 | {1, 9}, 75 | {9, 6}, 76 | {6, 15}, 77 | {15, 5} 78 | }; 79 | #ifdef PYNQ_HAS_I2C 80 | i2c i2c_open_grove(int grove_id) { 81 | if (grove_id == ARDUINO_SEEED_I2C || grove_id == ARDUINO_DIGILENT_I2C) { 82 | return i2c_open_device(0); 83 | #ifdef XPAR_IO_SWITCH_NUM_INSTANCES 84 | #ifdef XPAR_IO_SWITCH_0_I2C0_BASEADDR 85 | } else if (grove_id <= GROVE_I2C_MAX) { 86 | return i2c_open(digital_pins[grove_id][1], 87 | digital_pins[grove_id][0]); 88 | #endif 89 | #endif 90 | } else { 91 | return -1; 92 | } 93 | } 94 | #endif 95 | 96 | #ifdef PYNQ_HAS_GPIO 97 | static gpio gpio_open_grove_internal(int grove_id, int pin_id) { 98 | return gpio_open(digital_pins[grove_id][pin_id]); 99 | }; 100 | 101 | gpio gpio_open_grove(int grove_id) { 102 | return gpio_open_grove_internal(grove_id, 0); 103 | } 104 | gpio gpio_open_grove_a(int grove_id) { 105 | return gpio_open_grove_internal(grove_id, 0); 106 | } 107 | gpio gpio_open_grove_b(int grove_id) { 108 | return gpio_open_grove_internal(grove_id, 1); 109 | } 110 | #endif 111 | 112 | #ifdef PYNQ_HAS_UART 113 | uart uart_open_grove(int grove_id) { 114 | if (grove_id <= GROVE_UART_MAX) { 115 | return uart_open(digital_pins[grove_id][1], 116 | digital_pins[grove_id][0]); 117 | } else { 118 | return -1; 119 | } 120 | } 121 | #endif 122 | 123 | static analog analog_open_grove_internal(int grove_id, int pin) { 124 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) { 125 | return analog_open_xadc(analog_pins[grove_id - ARDUINO_DIGILENT_A1][pin]); 126 | } else { 127 | return -1; 128 | } 129 | } 130 | 131 | analog analog_open_grove(int grove_id) { 132 | return analog_open_grove_internal(grove_id, 0); 133 | } 134 | analog analog_open_grove_a(int grove_id) { 135 | return analog_open_grove_internal(grove_id, 0); 136 | } 137 | analog analog_open_grove_b(int grove_id) { 138 | return analog_open_grove_internal(grove_id, 1); 139 | } 140 | 141 | static timer timer_open_grove_internal(int grove_id, int pin_id) { 142 | timer device = timer_open_device(0); 143 | init_io_switch(); 144 | set_pin(digital_pins[grove_id][pin_id], PWM0); 145 | return device; 146 | }; 147 | 148 | timer timer_open_grove(int grove_id) { 149 | return timer_open_grove_internal(grove_id, 0); 150 | } 151 | timer timer_open_grove_a(int grove_id) { 152 | return timer_open_grove_internal(grove_id, 0); 153 | } 154 | timer timer_open_grove_b(int grove_id) { 155 | return timer_open_grove_internal(grove_id, 1); 156 | } 157 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_joystick/include/grove_joystick.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Joystick class 41 | * 42 | * Available Methods: 43 | * open, close, x, y, is_clicked 44 | * 45 | */ 46 | typedef py_int grove_joystick; 47 | 48 | // Device lifetime functions 49 | /* Open a Joystick device connected to the specified port 50 | * 51 | * Parameters 52 | * ---------- 53 | * grove_id: int 54 | * Valid port ids for this device: 55 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 56 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 57 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 58 | * 59 | * Returns 60 | * ------- 61 | * grove_joystick 62 | * The device object 63 | * 64 | */ 65 | grove_joystick grove_joystick_open(int grove_id); 66 | 67 | /* Release the Joystick by closing the device 68 | * 69 | * Parameters 70 | * ---------- 71 | * None 72 | * 73 | * Returns 74 | * ------- 75 | * None 76 | * 77 | */ 78 | void grove_joystick_close(grove_joystick joystick); 79 | 80 | // Device functions 81 | /* Returns posotion of the Joystick 82 | * 83 | * Returns the X-Coordinate of the Joystick 84 | * 85 | * Parameters 86 | * ---------- 87 | * None 88 | * 89 | * Returns 90 | * ------- 91 | * A float value if successful 92 | * 93 | */ 94 | py_float grove_joystick_x(grove_joystick joystick); 95 | 96 | /* Returns posotion of the Joystick 97 | * 98 | * Returns the Y-Coordinate of the Joystick 99 | * 100 | * Parameters 101 | * ---------- 102 | * None 103 | * 104 | * Returns 105 | * ------- 106 | * A float value if successful 107 | * 108 | */ 109 | py_float grove_joystick_y(grove_joystick joystick); 110 | 111 | /* Returns a valid value if the Joystick is clicked 112 | * 113 | * 114 | * Parameters 115 | * ---------- 116 | * None 117 | * 118 | * Returns 119 | * ------- 120 | * A 1 value if joystick is clicked 121 | */ 122 | py_int grove_joystick_is_clicked(grove_joystick joystick); 123 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_joystick/notebooks/grove_joystick.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Grove Thumb Joystick module\n", 8 | "---" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Aim\n", 16 | "\n", 17 | "* This notebook illustrates how to use available APIs for the Grove Thumb Joystick module on PYNQ-Z2 Arduino interface.\n", 18 | "\n", 19 | "\n", 20 | "## References\n", 21 | "* [Grove Thumb Joystick](https://www.seeedstudio.com/Grove-Thumb-Joystick.html) \n", 22 | "* [Grove Base Shield V2.0](https://www.seeedstudio.com/Base-Shield-V2.html) \n", 23 | "\n", 24 | "## Last revised\n", 25 | "* 01 April 2021\n", 26 | " + Initial version\n", 27 | "---" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Load _base_ Overlay" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "
\n", 42 | "Note that we load the base bitstream only once
\n", 43 | "Please make sure you run the following cell before running other cells \n", 44 | "
" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "from pynq.overlays.base import BaseOverlay\n", 54 | "from pynq_peripherals import ArduinoSEEEDGroveAdapter, PmodGroveAdapter\n", 55 | "from time import sleep\n", 56 | "base = BaseOverlay('base.bit')" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Using Grove Thumb Joystick with Grove Base Shield V2.0 (Arduino)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "
    \n", 71 | "

    Make Physical Connections

    \n", 72 | "
  • Insert the SEEED Grove Base Shield into the Arduino connector on the board. Connect the Thumb Joystick module to A1 connector of the Grove Base Shield.
  • \n", 73 | "
\n", 74 | "
" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "### Adapter configuration" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "adapter = ArduinoSEEEDGroveAdapter(base.ARDUINO, A1='grove_joystick')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "### Define device object" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "joystick = adapter.A1" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "### Reading the coordinate" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "for i in range(10):\n", 123 | " print(f'(X, Y) = ({joystick.x():.2f}, {joystick.y():.2f})')\n", 124 | " sleep(1)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": {}, 130 | "source": [ 131 | "### Detect if Thumb Joystick is clicked" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "for i in range(10):\n", 141 | " if joystick.is_clicked():\n", 142 | " print('joystick is clicked')\n", 143 | " sleep(1)" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "Copyright (C) 2021 Xilinx, Inc\n", 151 | "\n", 152 | "SPDX-License-Identifier: BSD-3-Clause" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "---" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "----" 167 | ] 168 | } 169 | ], 170 | "metadata": { 171 | "kernelspec": { 172 | "display_name": "Python 3", 173 | "language": "python", 174 | "name": "python3" 175 | }, 176 | "language_info": { 177 | "codemirror_mode": { 178 | "name": "ipython", 179 | "version": 3 180 | }, 181 | "file_extension": ".py", 182 | "mimetype": "text/x-python", 183 | "name": "python", 184 | "nbconvert_exporter": "python", 185 | "pygments_lexer": "ipython3", 186 | "version": "3.6.5" 187 | } 188 | }, 189 | "nbformat": 4, 190 | "nbformat_minor": 4 191 | } 192 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_joystick/src/grove_joystick.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | #define DEVICE_MAX 4 37 | 38 | struct info { 39 | analog X; 40 | analog Y; 41 | int count; 42 | }; 43 | 44 | static struct info info[DEVICE_MAX]; 45 | 46 | /* 47 | * Documentation for public functions is provided as part of the external 48 | * public header file. 49 | * Documentation for static/private functions is provided above each 50 | * function in this file. 51 | */ 52 | 53 | /* Get next instance space 54 | * 55 | * Parameters 56 | * ---------- 57 | * None 58 | * 59 | * Return 60 | * ------ 61 | * int 62 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 63 | * 64 | */ 65 | static int next_index() { 66 | for (int i = 0; i < DEVICE_MAX; ++i) { 67 | if (info[i].count == 0) return i; 68 | } 69 | return -ENOMEM; 70 | } 71 | grove_joystick grove_joystick_open(int grove_id) { 72 | grove_joystick dev_id = next_index(); 73 | if (dev_id >= 0) { 74 | info[dev_id].count++; 75 | info[dev_id].X = analog_open_grove_a(grove_id); 76 | info[dev_id].Y = analog_open_grove_b(grove_id); 77 | } 78 | return dev_id; 79 | } 80 | 81 | void grove_joystick_close(grove_joystick joystick) { 82 | if (--info[joystick].count != 0) return; 83 | analog X = info[joystick].X; 84 | analog Y = info[joystick].Y; 85 | analog_close(X); 86 | analog_close(Y); 87 | } 88 | 89 | py_float grove_joystick_x(grove_joystick joystick) { 90 | analog X = info[joystick].X; 91 | int x_raw = analog_get_raw(X); 92 | int x_max = analog_get_max(X); 93 | return (float)(x_max-x_raw)*10/x_raw; 94 | } 95 | 96 | py_float grove_joystick_y(grove_joystick joystick) { 97 | analog Y = info[joystick].Y; 98 | int y_raw = analog_get_raw(Y); 99 | int y_max = analog_get_max(Y); 100 | return (float)(y_max-y_raw)*10/y_raw; 101 | } 102 | 103 | py_int grove_joystick_is_clicked(grove_joystick joystick) { 104 | float X = grove_joystick_x(joystick); 105 | if (X < 0.1) { 106 | return 1; 107 | } else { 108 | return PY_SUCCESS; 109 | } 110 | } -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_led_stick/include/grove_led_stick.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Led_stick class 41 | * 42 | * Available Methods: 43 | * open, close, stick_show, set_pixel, clear 44 | * 45 | */ 46 | typedef py_int grove_led_stick; 47 | 48 | // Device lifetime functions 49 | /* Open an Led_stick device connected to the specified port 50 | * 51 | * Parameters 52 | * ---------- 53 | * grove_id: int 54 | * Valid port ids for this device: 55 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 56 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 57 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 58 | * 59 | * Returns 60 | * ------- 61 | * led_stick 62 | * The device object 63 | * 64 | */ 65 | grove_led_stick grove_led_stick_open(int grove_id); 66 | 67 | /* Release the Led_stick by closing the device 68 | * 69 | * Parameters 70 | * ---------- 71 | * None 72 | * 73 | * Returns 74 | * ------- 75 | * None 76 | * 77 | */ 78 | void grove_led_stick_close(grove_led_stick led_stick); 79 | 80 | // Device functions 81 | /* Display the light pattern on all the Leds in the grove Led_stick 82 | * 83 | * Parameters 84 | * ---------- 85 | * None 86 | * 87 | * Returns 88 | * ------- 89 | * None 90 | * 91 | */ 92 | py_void grove_led_stick_show(grove_led_stick led_stick); 93 | 94 | /* set the grove Led_stick leds by unique led number and color 95 | * 96 | * Parameters 97 | * ---------- 98 | * number: int 99 | * The position of the led 100 | * RGB: int 101 | * Sets the color of the led to this value 102 | * 103 | * Returns 104 | * ------- 105 | * None 106 | * 107 | */ 108 | py_void grove_led_stick_set_pixel(grove_led_stick led_stick, int number, unsigned int RGB); 109 | 110 | /* Clear all Leds 111 | * 112 | * Parameters 113 | * ---------- 114 | * None 115 | * 116 | * Returns 117 | * ------- 118 | * None 119 | * 120 | */ 121 | py_void grove_led_stick_clear(grove_led_stick led_stick); 122 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_ledbar/include/grove_ledbar.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* ledbar class 42 | * 43 | * Available Methods: 44 | * open, close, set_level, set_pixel, read, clear 45 | * 46 | */ 47 | typedef py_int grove_ledbar; 48 | 49 | // Device lifetime functions 50 | /* Open an ledbar device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_ledbar 63 | * The device object 64 | * 65 | */ 66 | grove_ledbar grove_ledbar_open(int grove_id); 67 | 68 | /* Release the ledbar by closing the device 69 | * 70 | * Parameters 71 | * ---------- 72 | * None 73 | * 74 | * Returns 75 | * ------- 76 | * None 77 | * 78 | */ 79 | void grove_ledbar_close(grove_ledbar ledbar); 80 | 81 | 82 | // Device functions 83 | /* Lit the leds from 1 to the specified level in the specified direction with thee sepcified intensity 84 | * 85 | * Parameters 86 | * ---------- 87 | * level: int 88 | * The level is the led number it lit to (1 being the left most led, valid value 1 to 10) 89 | * intensity: int 90 | * Can be 1,2 or 3 based on Low, Med or High Intensity 91 | * inverse: int 92 | * Direction left-to-right (Red-to-Green) when 0, right-to-left (green-to-red) when 1 93 | * 94 | * Returns 95 | * ------- 96 | * None 97 | * 98 | */ 99 | py_void grove_ledbar_set_level(grove_ledbar ledbar, int level, int intensity, int inverse); 100 | 101 | /* Set a pixel (led) to ON state with desired intensity 102 | * 103 | * Parameters 104 | * ---------- 105 | * index: int 106 | * The positon of the Led from 0-9 107 | * intensity: int 108 | * Can be 1, 2 or 3 for Low, Med or High intensity respectively 109 | * 110 | * Returns 111 | * ------- 112 | * None 113 | * 114 | */ 115 | py_void grove_ledbar_set_pixel(grove_ledbar ledbar, int index, int intensity); 116 | 117 | /* Read the current state of the ledbar 118 | * 119 | * Parameters 120 | * ---------- 121 | * None 122 | * 123 | * Returns 124 | * ------- 125 | * bits: int 126 | * Binary value of the ledbar state, lsb represents index 0 or red led status 127 | */ 128 | py_int grove_ledbar_read(grove_ledbar ledbar); 129 | 130 | /* Clear the state of the ledbar 131 | * 132 | * Parameters 133 | * ---------- 134 | * None 135 | * 136 | * Returns 137 | * ------- 138 | * None 139 | * 140 | */ 141 | py_void grove_ledbar_clear(grove_ledbar ledbar); 142 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_lgcp/include/grove_lgcp_hw.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #define REG_RAM 0x00 //~0X7F 34 | #define REG_ENABLE 0x80 35 | #define REG_ATIME 0x81 36 | #define REG_WTIME 0x83 37 | #define REG_ALS_IT 0x84 //~0X87 38 | #define REG_PROX_IT_L 0x89 39 | #define REG_PROX_IT_H 0x8B 40 | #define REG_IT_PERS 0x8C 41 | #define REG_CONFIG1 0x8D 42 | #define REG_PPULSE 0x8E 43 | #define REG_CONTROL 0x8F 44 | #define REG_CONFIG2 0x90 45 | #define REG_REVID 0x91 46 | #define REG_ID 0x92 47 | #define REG_STATUS 0x93 48 | #define REG_RGBC_DATA 0x94 //~9B 49 | #define REG_PROX_DATA 0x9C 50 | #define REG_POFFSET_NE 0x9D 51 | #define REG_POFFSET_SW 0x9E 52 | #define REG_CONFIG3 0x9F 53 | 54 | //The following CONFIG registers have different definations under different modes 55 | #define REG_CONFIG_A0 0xA0 56 | #define REG_CONFIG_A1 0xA1 57 | #define REG_CONFIG_A2 0xA2 58 | #define REG_CONFIG_A3 0xA3 59 | #define REG_CONFIG_A4 0xA4 60 | #define REG_CONFIG_A5 0xA5 61 | #define REG_CONFIG_A6 0xA6 62 | #define REG_CONFIG_A7 0xA7 63 | #define REG_CONFIG_A8 0xA8 64 | #define REG_CONFIG_A9 0xA9 65 | #define REG_CONFIG_AA 0xAA 66 | #define REG_CONFIG_AB 0xAB 67 | #define REG_CONFIG_AC 0xAC 68 | #define REG_CONFIG_AE 0xAE 69 | #define REG_CONFIG_AF 0xAF 70 | 71 | #define REG_PBCLEAR 0xE3 72 | #define REG_IFORCE 0xE4 73 | #define REG_PICLEAR 0xE5 74 | #define REG_CICLEAR 0xE6 75 | #define REG_AICLEAR 0xE7 76 | #define REG_GFIFO_N 0xFC 77 | #define REG_GFIFO_S 0xFD 78 | #define REG_GFIFO_W 0xFE 79 | #define REG_GFIFO_E 0xFF 80 | 81 | //Enable bits 82 | #define ENABLE_PON 0x01 83 | #define ENABLE_AEN 0x02 84 | #define ENABLE_PEN 0x04 85 | #define ENABLE_WEN 0x08 86 | #define ENABLE_AIEN 0x10 87 | #define ENABLE_PIEN 0x20 88 | #define ENABLE_GEN 0x40 89 | #define ENABLE_PBEN 0x80 90 | 91 | //Status bits 92 | #define STATUS_AVALID (1) 93 | #define STATUS_PVALID (1<<1) 94 | #define STATUS_GINT (1<<2) 95 | #define STATUS_PBINT (1<<3) 96 | #define STATUS_AINT (1<<4) 97 | #define STATUS_PINT (1<<5) 98 | #define STATUS_PGSAT (1<<6) 99 | #define STATUS_CPSAT (1<<7) 100 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_light/include/grove_light.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Device typedef 41 | 42 | /* Light class 43 | * 44 | * Available Methods: 45 | * open, close, read 46 | * read returns light intensity in percentage 47 | * 48 | */ 49 | typedef py_int grove_light; 50 | 51 | // Device lifetime functions 52 | /* Open a Light module connected directly to one of Arduino analog ports 53 | * or via a Grove ADC module (at default address) to an I2C port 54 | * 55 | * Parameters 56 | * ---------- 57 | * grove_id: int 58 | * Valid port ids for this device: 59 | * ARDUINO_SEEED_A0, ARDUINO_SEEED_A1, ARDUINO_SEEED_A2, ARDUINO_SEEED_A3 60 | * 61 | * Returns 62 | * ------- 63 | * grove_temperature 64 | * The device object if successful 65 | * -EIO device not present (raises exception) 66 | * -ENOMEM memory allocation error (raises exception) 67 | * 68 | */ 69 | grove_light grove_light_open(int grove_id); 70 | 71 | /* Open a light module connected to Grove_ADC module 72 | * 73 | * Parameters 74 | * ---------- 75 | * grove_id: int 76 | * Valid port ids for this device: 77 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 78 | * address: int 79 | * I2C address of the ADC 80 | * 81 | * Returns 82 | * ------- 83 | * grove_temperature 84 | * The device object if successful 85 | * -EIO device not present (raises exception) 86 | * -ENOMEM memory allocation error (raises exception) 87 | * 88 | */ 89 | grove_light grove_light_open_at_address(int grove_id, int address); 90 | 91 | /* Release the light module by closing the device 92 | * 93 | * Parameters 94 | * ---------- 95 | * grove_id : int 96 | * The opened device object 97 | * 98 | * Returns 99 | * ------- 100 | * None 101 | * 102 | */ 103 | void grove_light_close(grove_light light); 104 | 105 | // Device functions 106 | /* Read the connected device and return the light intensity in percentage 107 | * 108 | * Parameters 109 | * ---------- 110 | * None 111 | * 112 | * Returns 113 | * ------- 114 | * float: 115 | * light intensity in percentage 116 | * NAN general operation error (raises exception) 117 | * 118 | */ 119 | py_float grove_light_get_intensity(grove_light light); 120 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_light/src/grove_light.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include "grove_constants.h" 35 | #include 36 | #include 37 | 38 | #define DEVICE_MAX 4 39 | 40 | struct info { 41 | analog pin; 42 | int count; 43 | }; 44 | 45 | static struct info info[DEVICE_MAX]; 46 | 47 | /* 48 | * Documentation for public functions is provided as part of the external 49 | * public header file. 50 | * Documentation for static/private functions is provided above each 51 | * function in this file. 52 | */ 53 | 54 | /* Get next instance space 55 | * 56 | * Parameters 57 | * ---------- 58 | * None 59 | * 60 | * Return 61 | * ------ 62 | * int 63 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 64 | * 65 | */ 66 | static int next_index() { 67 | for (int i = 0; i < DEVICE_MAX; ++i) { 68 | if (info[i].count == 0) return i; 69 | } 70 | return -ENOMEM; 71 | } 72 | 73 | static grove_light grove_light_open_analog(analog pin) { 74 | grove_light dev_id = next_index(); 75 | if (dev_id >= 0) { 76 | info[dev_id].count++; 77 | info[dev_id].pin = pin; 78 | } 79 | return dev_id; 80 | } 81 | 82 | grove_light grove_light_open(int grove_id) { 83 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) 84 | return grove_light_open_analog(analog_open_grove(grove_id)); 85 | else 86 | return grove_light_open_analog(analog_open_grove_adc(grove_adc_open(grove_id))); 87 | } 88 | 89 | grove_light grove_light_open_at_address(int grove_id, int address) { 90 | return grove_light_open_analog(analog_open_grove_adc(grove_adc_open_at_address(grove_id, address))); 91 | } 92 | 93 | void grove_light_close(grove_light light) { 94 | if (--info[light].count != 0) return; 95 | analog pin = info[light].pin; 96 | analog_close(pin); 97 | } 98 | 99 | py_float grove_light_get_intensity(grove_light light) { 100 | analog pin = info[light].pin; 101 | return (float)analog_get_voltage(pin) * 100.0 / (float)analog_get_reference(pin); 102 | } 103 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_line_finder/include/grove_line_finder.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Line_finder class 41 | * 42 | * Available Methods: 43 | * open, close, read 44 | * 45 | */ 46 | typedef py_int grove_line_finder; 47 | 48 | // Device lifetime functions 49 | /* Open a Line_finder device connected to the specified port 50 | * 51 | * Parameters 52 | * ---------- 53 | * grove_id: int 54 | * Valid port ids for this device: 55 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 56 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 57 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 58 | * 59 | * Returns 60 | * ------- 61 | * line_finder 62 | * The device object 63 | * 64 | */ 65 | grove_line_finder grove_line_finder_open(int grove_id); 66 | 67 | /* Release the Line_finder by closing the device 68 | * 69 | * Parameters 70 | * ---------- 71 | * None 72 | * 73 | * Returns 74 | * ------- 75 | * None 76 | * 77 | */ 78 | void grove_line_finder_close(grove_line_finder line_finder); 79 | 80 | // Device functions 81 | /* Read the Line_finder and return integer value 82 | * 83 | * Parameters 84 | * ---------- 85 | * None 86 | * 87 | * Returns 88 | * ------- 89 | * True, if line_found 90 | * False, if line_found 91 | * 92 | */ 93 | py_bool grove_line_finder_line_found(grove_line_finder line_finder); 94 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_line_finder/src/grove_line_finder.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | #define DEVICE_MAX 4 37 | 38 | struct info { 39 | gpio pin; 40 | int count; 41 | }; 42 | 43 | static struct info info[DEVICE_MAX]; 44 | 45 | /* 46 | * Documentation for public functions is provided as part of the external 47 | * public header file. 48 | * Documentation for static/private functions is provided above each 49 | * function in this file. 50 | */ 51 | 52 | /* Get next instance space 53 | * 54 | * Parameters 55 | * ---------- 56 | * None 57 | * 58 | * Return 59 | * ------ 60 | * int 61 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 62 | * 63 | */ 64 | static int next_index() { 65 | for (int i = 0; i < DEVICE_MAX; ++i) { 66 | if (info[i].count == 0) return i; 67 | } 68 | return -ENOMEM; 69 | } 70 | grove_line_finder grove_line_finder_open(int grove_id) { 71 | grove_line_finder dev_id = next_index(); 72 | if (dev_id >= 0) { 73 | info[dev_id].count++; 74 | info[dev_id].pin = gpio_open_grove(grove_id); 75 | gpio_set_direction(info[dev_id].pin, GPIO_IN); 76 | } 77 | return dev_id; 78 | } 79 | 80 | void grove_line_finder_close(grove_line_finder line_finder) { 81 | if (--info[line_finder].count != 0) return; 82 | gpio pin = info[line_finder].pin; 83 | gpio_close(pin); 84 | } 85 | 86 | py_bool grove_line_finder_line_found(grove_line_finder line_finder) { 87 | gpio pin = info[line_finder].pin; 88 | return gpio_read(pin); 89 | } 90 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_ph/include/grove_ph.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Device typedef 41 | 42 | /* PH class 43 | * 44 | * Available Methods: 45 | * open, close, read, first_calibrate, second_calibrate, get_ph 46 | * 47 | */ 48 | typedef py_int grove_ph; 49 | 50 | // Device lifetime functions 51 | /* Open a PH module connected directly to one of Arduino analog ports 52 | * or via a Grove ADC module (at default address) to an I2C port 53 | * 54 | * Parameters 55 | * ---------- 56 | * grove_id: int 57 | * Valid port ids for this device: 58 | * ARDUINO_SEEED_A0, ARDUINO_SEEED_A1, ARDUINO_SEEED_A2, ARDUINO_SEEED_A3 59 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C (via I2C ADC) 60 | * 61 | * Returns 62 | * ------- 63 | * grove_ph 64 | * The device object if successful 65 | * -EIO device not present (raises exception) 66 | * -ENOMEM memory allocation error (raises exception) 67 | * 68 | */ 69 | grove_ph grove_ph_open(int grove_id); 70 | 71 | /* Open a PH module connected to Grove_ADC module 72 | * 73 | * Parameters 74 | * ---------- 75 | * grove_id: int 76 | * Valid port ids for this device: 77 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 78 | * address: int 79 | * I2C address of the ADC 80 | * 81 | * Returns 82 | * ------- 83 | * grove_ph 84 | * The device object if successful 85 | * -EIO device not present (raises exception) 86 | * -ENOMEM memory allocation error (raises exception) 87 | * 88 | */ 89 | grove_ph grove_ph_open_at_address(int grove_id, int address); 90 | 91 | /* Release the PH module by closing the device 92 | * 93 | * Parameters 94 | * ---------- 95 | * grove_id : int 96 | * The opened device object 97 | * 98 | * Returns 99 | * ------- 100 | * None 101 | * 102 | */ 103 | void grove_ph_close(grove_ph ph); 104 | 105 | // Device functions 106 | /* Read the connected device and return the PH in range of 0-14 107 | * 108 | * Parameters 109 | * ---------- 110 | * None 111 | * 112 | * Returns 113 | * ------- 114 | * float: 115 | * PH value in range of 0-14 116 | * NAN general operation error (raises exception) 117 | * 118 | */ 119 | py_float grove_ph_get_ph(grove_ph ph); 120 | 121 | /* Calibrate the connected device (1/2) and return the voltage 122 | * 123 | * Parameters 124 | * ---------- 125 | * ph : float 126 | * The known pH value labeled on the buffer fluid. 127 | * 128 | * Returns 129 | * ------- 130 | * float: 131 | * voltage value 132 | * NAN general operation error (raises exception) 133 | * 134 | */ 135 | py_float grove_ph_first_calibrate(grove_ph p, float ph); 136 | 137 | /* Calibrate the connected device (2/2) and return the voltage 138 | * 139 | * Parameters 140 | * ---------- 141 | * ph : float 142 | * The known pH value labeled on the buffer fluid. 143 | * 144 | * Returns 145 | * ------- 146 | * float: 147 | * voltage value 148 | * NAN general operation error (raises exception) 149 | * 150 | */ 151 | py_float grove_ph_second_calibrate(grove_ph p, float ph); -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_ph/src/grove_ph.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include "grove_constants.h" 37 | #include 38 | 39 | #define DEVICE_MAX 4 40 | 41 | struct info { 42 | analog pin; 43 | int count; 44 | }; 45 | 46 | static struct info info[DEVICE_MAX]; 47 | 48 | float vol_1 = 1.66; 49 | float ph_1 = 9.18; 50 | float vol_2 = 1.93; 51 | float ph_2 = 4.00; 52 | float k = -19.18518519; 53 | float offset = 41.02740741; 54 | 55 | /* 56 | * Documentation for public functions is provided as part of the external 57 | * public header file. 58 | * Documentation for static/private functions is provided above each 59 | * function in this file. 60 | */ 61 | 62 | /* Get next instance space 63 | * 64 | * Parameters 65 | * ---------- 66 | * None 67 | * 68 | * Return 69 | * ------ 70 | * int 71 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 72 | * 73 | */ 74 | static int next_index() { 75 | for (int i = 0; i < DEVICE_MAX; ++i) { 76 | if (info[i].count == 0) return i; 77 | } 78 | return -ENOMEM; 79 | } 80 | 81 | static grove_ph grove_ph_open_analog(analog pin) { 82 | grove_ph dev_id = next_index(); 83 | if (dev_id >= 0) { 84 | info[dev_id].count++; 85 | info[dev_id].pin = pin; 86 | } 87 | return dev_id; 88 | } 89 | 90 | grove_ph grove_ph_open(int grove_id) { 91 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) 92 | return grove_ph_open_analog(analog_open_grove(grove_id)); 93 | else 94 | return grove_ph_open_analog(analog_open_grove_adc(grove_adc_open(grove_id))); 95 | } 96 | 97 | grove_ph grove_ph_open_at_address(int grove_id, int address) { 98 | return grove_ph_open_analog(analog_open_grove_adc(grove_adc_open_at_address(grove_id, address))); 99 | } 100 | 101 | void grove_ph_close(grove_ph ph) { 102 | if (--info[ph].count != 0) return; 103 | analog pin = info[ph].pin; 104 | analog_close(pin); 105 | } 106 | 107 | py_float grove_ph_first_calibrate(grove_ph p, float ph) { 108 | if (ph < 7 || ph > 14) return -1; 109 | ph_1 = ph; 110 | analog pin = info[p].pin; 111 | vol_1 = (float)analog_get_voltage(pin); 112 | return vol_1; 113 | } 114 | 115 | py_float grove_ph_second_calibrate(grove_ph p, float ph) { 116 | if (ph < 0 || ph > 7) return -1; 117 | ph_2 = ph; 118 | analog pin = info[p].pin; 119 | vol_2 = (float)analog_get_voltage(pin); 120 | return vol_2; 121 | } 122 | 123 | py_float grove_ph_get_ph(grove_ph ph) { 124 | analog pin = info[ph].pin; 125 | float current_voltage = (float)analog_get_voltage(pin); 126 | k = (ph_2 - ph_1) / (vol_2 - vol_1); 127 | offset = ((ph_2 + ph_1) - k*(vol_1 + vol_2))*0.5; 128 | float raw_value = k*current_voltage + offset; 129 | raw_value = (raw_value > 14) ? 14 : raw_value; 130 | raw_value = (raw_value < 0 ) ? 0 : raw_value; 131 | return raw_value; 132 | } 133 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_pir/include/grove_pir.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* Motion sensor Class 42 | * 43 | * Available Methods: 44 | * open, close, motion 45 | * 46 | */ 47 | typedef int grove_pir; 48 | 49 | // Device lifetime functions 50 | 51 | /* Open a Motion sensor device connected to the specified port 52 | * 53 | * Parameters 54 | * ---------- 55 | * grove_id: int 56 | * Valid port ids for this device: 57 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 58 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 59 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 60 | * 61 | * Returns 62 | * ------- 63 | * grove_pir 64 | * The device object 65 | * -ENOMEM memory allocation error (raises exception) 66 | * 67 | */ 68 | grove_pir grove_pir_open(int grove_id); 69 | 70 | /* Release the Motion sensor by closing the device 71 | * 72 | * Parameters 73 | * ---------- 74 | * None 75 | * 76 | * Returns 77 | * ------- 78 | * None 79 | * 80 | */ 81 | void grove_pir_close(grove_pir pir); 82 | 83 | 84 | // Device functions 85 | 86 | /* Sense if motion is present 87 | * 88 | * Parameters 89 | * ---------- 90 | * None 91 | * 92 | * Returns 93 | * ------- 94 | * True, if motion detected 95 | * False, if motion not detected 96 | * 97 | */ 98 | py_bool grove_pir_motion_detected(grove_pir pir); 99 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_pir/notebooks/grove_pir.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Grove PIR module\n", 8 | "---" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Aim\n", 16 | "\n", 17 | "* This notebook illustrates how to use available APIs for the Grove PIR module on PYNQ-Z2 Arduino and PMOD interfaces.\n", 18 | "\n", 19 | "\n", 20 | "## References\n", 21 | "* [Grove PIR](https://www.seeedstudio.com/Grove-PIR-Motion-Sensor.html) \n", 22 | "* [PYNQ Grove Adapter](https://store.digilentinc.com/pynq-grove-system-add-on-board/) \n", 23 | "* [Grove Base Shield V2.0](https://www.seeedstudio.com/Base-Shield-V2.html) \n", 24 | "\n", 25 | "## Last revised\n", 26 | "* 01 April 2021\n", 27 | " + Initial version\n", 28 | "---" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "## Load _base_ Overlay" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "
\n", 43 | "Note that we load the base bitstream only once to use Grove module with PYNQ Grove Adapter and SEEED Grove Base Shield V2.0
\n", 44 | "Please make sure you run the following before running either of the interfaces \n", 45 | "
" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "from pynq.overlays.base import BaseOverlay\n", 55 | "from pynq_peripherals import ArduinoSEEEDGroveAdapter, PmodGroveAdapter\n", 56 | "base = BaseOverlay('base.bit')" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Using Grove PIR with Grove Base Shield V2.0 (Arduino)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "
    \n", 71 | "

    Make Physical Connections

    \n", 72 | "
  • Insert the Grove Base Shield into the Arduino connector on the board. Connect the Grove PIR module to D6 connector of the Grove Base Shield.
  • \n", 73 | "
\n", 74 | "
" 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "### Adapter configuration" 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": null, 87 | "metadata": {}, 88 | "outputs": [], 89 | "source": [ 90 | "adapter = ArduinoSEEEDGroveAdapter(base.ARDUINO, D6='grove_pir')" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "### Define device object" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": null, 103 | "metadata": {}, 104 | "outputs": [], 105 | "source": [ 106 | "motion_sensor = adapter.D6" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "### Reading from the Grove PIR" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [ 122 | "from time import sleep\n", 123 | "\n", 124 | "sample_interval = 0.2 #seconds\n", 125 | "number_of_samples = 25\n", 126 | "\n", 127 | "for i in range(number_of_samples):\n", 128 | " print('{:.1f}: {}'.format(i*sample_interval, \"motion detected\" if motion_sensor.motion_detected() else \"-\")) \n", 129 | " sleep(sample_interval)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "---\n", 137 | "## Using Grove PIR with PYNQ Grove Adapter (PMOD)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "
    \n", 145 | "

    Make Physical Connections

    \n", 146 | "
  • Connect the PYNQ Grove Adapter to PMODB connector. Connect the Grove PIR module to the G2 connector of the Adapter.
\n", 147 | "
" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "### Adapter configuration" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": null, 160 | "metadata": {}, 161 | "outputs": [], 162 | "source": [ 163 | "adapter = PmodGroveAdapter(base.PMODB, G2='grove_pir')" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "metadata": {}, 169 | "source": [ 170 | "### Define device object" 171 | ] 172 | }, 173 | { 174 | "cell_type": "code", 175 | "execution_count": null, 176 | "metadata": {}, 177 | "outputs": [], 178 | "source": [ 179 | "from time import sleep\n", 180 | "motion_sensor = adapter.G2" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "### Reading from the Grove PIR" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "from time import sleep\n", 197 | "\n", 198 | "sample_interval = 0.2 #seconds\n", 199 | "number_of_samples = 25\n", 200 | "\n", 201 | "for i in range(number_of_samples):\n", 202 | " print('{:.1f}: {}'.format(i*sample_interval, \"motion detected\" if motion_sensor.motion_detected() else \"-\")) \n", 203 | " sleep(sample_interval)" 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "metadata": {}, 209 | "source": [ 210 | "Copyright (C) 2021 Xilinx, Inc\n", 211 | "\n", 212 | "SPDX-License-Identifier: BSD-3-Clause" 213 | ] 214 | }, 215 | { 216 | "cell_type": "markdown", 217 | "metadata": {}, 218 | "source": [ 219 | "----" 220 | ] 221 | }, 222 | { 223 | "cell_type": "markdown", 224 | "metadata": {}, 225 | "source": [ 226 | "----" 227 | ] 228 | } 229 | ], 230 | "metadata": { 231 | "kernelspec": { 232 | "display_name": "Python 3", 233 | "language": "python", 234 | "name": "python3" 235 | }, 236 | "language_info": { 237 | "codemirror_mode": { 238 | "name": "ipython", 239 | "version": 3 240 | }, 241 | "file_extension": ".py", 242 | "mimetype": "text/x-python", 243 | "name": "python", 244 | "nbconvert_exporter": "python", 245 | "pygments_lexer": "ipython3", 246 | "version": "3.6.5" 247 | } 248 | }, 249 | "nbformat": 4, 250 | "nbformat_minor": 4 251 | } 252 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_pir/src/grove_pir.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | #define DEVICE_MAX 4 37 | 38 | struct info { 39 | gpio pin; 40 | int count; 41 | }; 42 | 43 | static struct info info[DEVICE_MAX]; 44 | 45 | static int next_index() { 46 | for (int i = 0; i < DEVICE_MAX; ++i) { 47 | if (info[i].count == 0) return i; 48 | } 49 | return -ENOMEM; 50 | } 51 | grove_pir grove_pir_open(int grove_id) { 52 | grove_pir dev_id = next_index(); 53 | info[dev_id].count++; 54 | info[dev_id].pin = gpio_open_grove(grove_id); 55 | gpio_set_direction(info[dev_id].pin, GPIO_IN); 56 | return dev_id; 57 | } 58 | 59 | void grove_pir_close(grove_pir pir) { 60 | if (--info[pir].count != 0) return; 61 | gpio pin = info[pir].pin; 62 | gpio_close(pin); 63 | } 64 | 65 | py_bool grove_pir_motion_detected(grove_pir pir) { 66 | gpio pin = info[pir].pin; 67 | return gpio_read(pin); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_potentiometer/include/grove_potentiometer.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* Potentiometer Class 42 | * 43 | * Available Methods: 44 | * open, close 45 | * 46 | * get_position 47 | */ 48 | 49 | typedef int grove_potentiometer; 50 | 51 | // Device lifetime functions 52 | 53 | /* Open a Potentiometer module connected directly to one of Arduino analog ports 54 | * or via a Grove ADC module (at default address) to an I2C port 55 | * 56 | * Parameters 57 | * ---------- 58 | * grove_id: int 59 | * Valid port ids for this device: 60 | * ARDUINO_SEEED_A0-A3 (analog) 61 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C (via I2C ADC) 62 | * 63 | * Returns 64 | * ------- 65 | * grove_potentiometer 66 | * The device object 67 | * -EIO device not present or IO error (raises exception) 68 | * -ENOMEM memory allocation error (raises exception) 69 | * 70 | */ 71 | grove_potentiometer grove_potentiometer_open(int grove_id); 72 | 73 | /* Open a Potentiometer module connected to the specified port with the default 74 | * I2C address 75 | * 76 | * Parameters 77 | * ---------- 78 | * grove_id: int 79 | * Valid port ids for this device: 80 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 81 | * address: int 82 | * I2C address of the ADC 83 | * 84 | * Returns 85 | * ------- 86 | * grove_potentiometer 87 | * The device object 88 | * -EIO device not present or IO error (raises exception) 89 | * -ENOMEM memory allocation error (raises exception) 90 | * 91 | */ 92 | grove_potentiometer grove_potentiometer_open_at_address(int grove_id, int address); 93 | 94 | /* Release the Potentiometer by closing the device 95 | * 96 | * Parameters 97 | * ---------- 98 | * grove_id : int 99 | * The opened device object 100 | * 101 | * Returns 102 | * ------- 103 | * None 104 | * 105 | */ 106 | void grove_potentiometer_close(grove_potentiometer potentiometer); 107 | 108 | 109 | // Device functions 110 | 111 | /* Read the ADC and return the linear or angular position as fraction of full displacement 112 | * 113 | * Parameters 114 | * ---------- 115 | * None 116 | * 117 | * Returns 118 | * ------- 119 | * float: 120 | * Linear or angular position as fraction of full displacement (between 0.0 and 1.0) 121 | * NAN general operation error (raises exception) 122 | * 123 | */ 124 | py_float grove_potentiometer_get_position(grove_potentiometer potentiometer); 125 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_potentiometer/src/grove_potentiometer.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include "grove_constants.h" 35 | #include 36 | #include 37 | 38 | #define MIN(a,b) ((a) < (b) ? a : b) 39 | 40 | #define DEVICE_MAX 4 41 | 42 | struct info { 43 | analog pin; 44 | int count; 45 | }; 46 | 47 | static struct info info[DEVICE_MAX]; 48 | const int R = 10000; // maximun resistance 49 | 50 | static int next_index() { 51 | for (int i = 0; i < DEVICE_MAX; ++i) { 52 | if (info[i].count == 0) return i; 53 | } 54 | return -1; 55 | } 56 | 57 | static grove_potentiometer grove_potentiometer_open_analog(analog pin) { 58 | grove_potentiometer dev_id = next_index(); 59 | if (dev_id >= 0) 60 | { 61 | info[dev_id].count++; 62 | info[dev_id].pin = pin; 63 | } 64 | return dev_id; 65 | } 66 | 67 | grove_potentiometer grove_potentiometer_open(int grove_id) { 68 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) 69 | return grove_potentiometer_open_analog(analog_open_grove(grove_id)); 70 | else 71 | return grove_potentiometer_open_analog(analog_open_grove_adc(grove_adc_open(grove_id))); 72 | } 73 | 74 | grove_potentiometer grove_potentiometer_open_at_address(int grove_id, int address) { 75 | return grove_potentiometer_open_analog(analog_open_grove_adc(grove_adc_open_at_address(grove_id, address))); 76 | } 77 | 78 | void grove_potentiometer_close(grove_potentiometer potentiometer) { 79 | if (--info[potentiometer].count != 0) return; 80 | analog pin = info[potentiometer].pin; 81 | analog_close(pin); 82 | } 83 | 84 | py_float grove_potentiometer_get_position(grove_potentiometer potentiometer) { 85 | analog pin = info[potentiometer].pin; 86 | float ration = analog_get_voltage(pin)/analog_get_reference(pin); 87 | return MIN(ration, 1.0); 88 | } 89 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_relay/include/grove_relay.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Relay class 41 | * 42 | * Available Methods: 43 | * open, close, on, off 44 | * 45 | */ 46 | typedef py_int grove_relay; 47 | 48 | // Device lifetime functions 49 | /* Open a Relay device connected to the specified port 50 | * 51 | * Parameters 52 | * ---------- 53 | * grove_id: int 54 | * Valid port ids for this device: 55 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 56 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 57 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 58 | * 59 | * Returns 60 | * ------- 61 | * grove_relay 62 | * The device object 63 | * 64 | */ 65 | grove_relay grove_relay_open(int grove_id); 66 | 67 | /* Release the Relay by closing the device 68 | * 69 | * Parameters 70 | * ---------- 71 | * None 72 | * 73 | * Returns 74 | * ------- 75 | * None 76 | * 77 | */ 78 | void grove_relay_close(grove_relay relay); 79 | 80 | // Device functions 81 | /* Switch on the Relay 82 | * 83 | * The Relay is switched ON, this can be confirmed by lit LED on the sensor module 84 | * 85 | * Parameters 86 | * ---------- 87 | * None 88 | * 89 | * Returns 90 | * ------- 91 | * None 92 | * 93 | */ 94 | py_void grove_relay_on(grove_relay relay); 95 | 96 | /* Switch off the Relay 97 | * 98 | * The Relay is switched OFF, this can be confirmed by off LED on the sensor module 99 | * 100 | * Parameters 101 | * ---------- 102 | * None 103 | * 104 | * Returns 105 | * ------- 106 | * None 107 | * 108 | */ 109 | py_void grove_relay_off(grove_relay relay); 110 | py_void grove_relay_off(grove_relay relay); -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_relay/notebooks/grove_relay.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Grove Relay module\n", 8 | "---" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Aim\n", 16 | "\n", 17 | "* This notebook illustrates how to use available APIs for the Grove Relay module on PYNQ-Z2 PMOD and Arduino interfaces.\n", 18 | "\n", 19 | "## References\n", 20 | "* [Grove Relay](https://www.seeedstudio.com/Grove-Relay.html) \n", 21 | "* [PYNQ Grove Adapter](https://store.digilentinc.com/pynq-grove-system-add-on-board/) \n", 22 | "* [Grove Base Shield V2.0](https://www.seeedstudio.com/Base-Shield-V2.html) \n", 23 | "\n", 24 | "## Last revised\n", 25 | "* 01 April 2021\n", 26 | " + Initial version\n", 27 | "---" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Load _base_ Overlay" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "
\n", 42 | "Note that we load the base bitstream only once to use Grove module with PYNQ Grove Adapter and SEEED Grove Base Shield V2.0
\n", 43 | "Please make sure you run the following cell before running either of the interfaces \n", 44 | "
" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 1, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "from pynq.overlays.base import BaseOverlay\n", 54 | "from pynq_peripherals import ArduinoSEEEDGroveAdapter, PmodGroveAdapter\n", 55 | "base = BaseOverlay('base.bit')" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "## Using Grove Relay with Grove Base Shield V2.0 (Arduino)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "
    \n", 70 | "

    Make Physical Connections

    \n", 71 | "
  • Insert the Grove Base Shield into the Arduino connector on the board. Connect the Grove Relay module to D6 connector of the Grove Base Shield.
  • \n", 72 | "
\n", 73 | "
" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "### Adapter configuration" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 2, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "adapter = ArduinoSEEEDGroveAdapter(base.ARDUINO, D6='grove_relay')" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "### Define device object" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 3, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "relay = adapter.D6" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "### Turn on the Grove Relay" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 4, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "relay.on()" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "### Turn off the Grove Relay" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 5, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "relay.off()" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "---\n", 145 | "## Using Grove Relay with PYNQ Grove Adapter (PMOD)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "markdown", 150 | "metadata": {}, 151 | "source": [ 152 | "
    \n", 153 | "

    Make Physical Connections

    \n", 154 | "
  • Connect the PYNQ Grove Adapter to PMODB connector. Connect the Grove Relay module to the G1 connector of the Adapter.
  • \n", 155 | "
\n", 156 | "
" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "### Adapter configuration" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 6, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "adapter = PmodGroveAdapter(base.PMODB, G1='grove_relay')" 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": {}, 178 | "source": [ 179 | "### Define device object" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": 7, 185 | "metadata": {}, 186 | "outputs": [], 187 | "source": [ 188 | "relay = adapter.G1" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": {}, 194 | "source": [ 195 | "### Turn on the Grove Relay" 196 | ] 197 | }, 198 | { 199 | "cell_type": "code", 200 | "execution_count": 9, 201 | "metadata": {}, 202 | "outputs": [], 203 | "source": [ 204 | "relay.on()" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "### Turn off the Grove Relay" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 10, 217 | "metadata": {}, 218 | "outputs": [], 219 | "source": [ 220 | "relay.off()" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "Copyright (C) 2021 Xilinx, Inc\n", 228 | "\n", 229 | "SPDX-License-Identifier: BSD-3-Clause" 230 | ] 231 | }, 232 | { 233 | "cell_type": "markdown", 234 | "metadata": {}, 235 | "source": [ 236 | "----" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "----" 244 | ] 245 | } 246 | ], 247 | "metadata": { 248 | "kernelspec": { 249 | "display_name": "Python 3", 250 | "language": "python", 251 | "name": "python3" 252 | }, 253 | "language_info": { 254 | "codemirror_mode": { 255 | "name": "ipython", 256 | "version": 3 257 | }, 258 | "file_extension": ".py", 259 | "mimetype": "text/x-python", 260 | "name": "python", 261 | "nbconvert_exporter": "python", 262 | "pygments_lexer": "ipython3", 263 | "version": "3.6.5" 264 | } 265 | }, 266 | "nbformat": 4, 267 | "nbformat_minor": 4 268 | } 269 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_relay/src/grove_relay.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #define DEVICE_MAX 4 38 | 39 | struct info { 40 | gpio pin; 41 | int count; 42 | }; 43 | 44 | static struct info info[DEVICE_MAX]; 45 | 46 | /* 47 | * Documentation for public functions is provided as part of the external 48 | * public header file. 49 | * Documentation for static/private functions is provided above each 50 | * function in this file. 51 | */ 52 | 53 | /* Get next instance space 54 | * 55 | * Parameters 56 | * ---------- 57 | * None 58 | * 59 | * Return 60 | * ------ 61 | * int 62 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 63 | * 64 | */ 65 | static int next_index() { 66 | for (int i = 0; i < DEVICE_MAX; ++i) { 67 | if (info[i].count == 0) return i; 68 | } 69 | return -ENOMEM; 70 | } 71 | grove_relay grove_relay_open(int grove_id) { 72 | grove_relay dev_id = next_index(); 73 | if (dev_id >= 0) { 74 | info[dev_id].count++; 75 | info[dev_id].pin = gpio_open_grove(grove_id); 76 | gpio_set_direction(info[dev_id].pin, GPIO_OUT); 77 | } 78 | return dev_id; 79 | } 80 | 81 | void grove_relay_close(grove_relay relay) { 82 | if (--info[relay].count != 0) return; 83 | gpio pin = info[relay].pin; 84 | gpio_write(pin, 0); 85 | gpio_close(pin); 86 | } 87 | 88 | py_void grove_relay_on(grove_relay relay) { 89 | gpio pin = info[relay].pin; 90 | gpio_write(pin, 1); 91 | return PY_SUCCESS; 92 | } 93 | 94 | py_void grove_relay_off(grove_relay relay) { 95 | gpio pin = info[relay].pin; 96 | gpio_write(pin, 0); 97 | return PY_SUCCESS; 98 | } 99 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_servo/include/grove_servo.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | /* Servo class 41 | * 42 | * Available Methods: 43 | * open, close 44 | * set_angular_position 45 | * 46 | */ 47 | typedef py_int grove_servo; 48 | 49 | // Device lifetime functions 50 | /* Open a Servo device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_servo 63 | * The device object 64 | * 65 | */ 66 | grove_servo grove_servo_open(int grove_id); 67 | 68 | /* Release the Servo by closing the device 69 | * 70 | * Parameters 71 | * ---------- 72 | * None 73 | * 74 | * Returns 75 | * ------- 76 | * None 77 | * 78 | */ 79 | void grove_servo_close(grove_servo p); 80 | 81 | // Device functions 82 | /* Set angle of the Servo device from 0 - 180 degrees 83 | * 84 | * Parameters 85 | * ---------- 86 | * angle: float 87 | * The angle of the Servo device from 0 - 180 degrees 88 | * 89 | * Returns 90 | * ------- 91 | * None 92 | * 93 | */ 94 | py_void grove_servo_set_angular_position(grove_servo p, float angle); 95 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_servo/notebooks/grove_servo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Grove Servo module\n", 8 | "---" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "## Aim\n", 16 | "\n", 17 | "* This notebook illustrates how to use available APIs for the Grove Servo module on PYNQ-Z2 PMOD and Arduino interfaces.\n", 18 | "\n", 19 | "## References\n", 20 | "* [Grove Servo](https://wiki.seeedstudio.com/Grove-Servo.html) \n", 21 | "* [PYNQ Grove Adapter](https://store.digilentinc.com/pynq-grove-system-add-on-board/) \n", 22 | "* [Grove Base Shield V2.0](https://www.seeedstudio.com/Base-Shield-V2.html) \n", 23 | "\n", 24 | "## Last revised\n", 25 | "* 01 April 2021\n", 26 | " + Initial version\n", 27 | "---" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Load _base_ Overlay" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "
\n", 42 | "Note that we load the base bitstream only once to use Grove module with PYNQ Grove Adapter and SEEED Grove Base Shield V2.0
\n", 43 | "Please make sure you run the following cell before running either of the interfaces \n", 44 | "
" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "from pynq.overlays.base import BaseOverlay\n", 54 | "from pynq_peripherals import ArduinoSEEEDGroveAdapter, PmodGroveAdapter\n", 55 | "base = BaseOverlay('base.bit')" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "## Using Grove Servo with Grove Base Shield V2.0 (Arduino)" 63 | ] 64 | }, 65 | { 66 | "cell_type": "markdown", 67 | "metadata": {}, 68 | "source": [ 69 | "
    \n", 70 | "

    Make Physical Connections

    \n", 71 | "
  • Insert the Grove Base Shield into the Arduino connector on the board. Connect the Grove Servo to D6 connector of the Grove Base Shield.
  • \n", 72 | "
\n", 73 | "
" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "### Adapter configuration" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "adapter = ArduinoSEEEDGroveAdapter(base.ARDUINO, D6='grove_servo')" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "### Define device object" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [], 104 | "source": [ 105 | "servo = adapter.D6" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "### Set Angle (range from 0 to 180)" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": null, 118 | "metadata": {}, 119 | "outputs": [], 120 | "source": [ 121 | "from time import sleep\n", 122 | "for angle in range(0, 180, 10):\n", 123 | " print(f\"{angle} degree\")\n", 124 | " servo.set_angular_position(angle)\n", 125 | " sleep(0.5)\n", 126 | "for angle in range(180, 0, -10):\n", 127 | " print(f\"{angle} degree\")\n", 128 | " servo.set_angular_position(angle)\n", 129 | " sleep(0.5)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "markdown", 134 | "metadata": {}, 135 | "source": [ 136 | "---\n", 137 | "## Using Grove Servo with PYNQ Grove Adapter (PMOD)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "
    \n", 145 | "

    Make Physical Connections

    \n", 146 | "
  • Connect the PYNQ Grove Adapter to PMODB connector. Connect the Grove Servo to the G1 connector of the Adapter.
  • \n", 147 | "
\n", 148 | "
" 149 | ] 150 | }, 151 | { 152 | "cell_type": "markdown", 153 | "metadata": {}, 154 | "source": [ 155 | "### Adapter configuration" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "metadata": {}, 162 | "outputs": [], 163 | "source": [ 164 | "adapter = PmodGroveAdapter(base.PMODB, G1='grove_servo')" 165 | ] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": {}, 170 | "source": [ 171 | "### Define device object" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": null, 177 | "metadata": {}, 178 | "outputs": [], 179 | "source": [ 180 | "servo = adapter.G1" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "metadata": {}, 186 | "source": [ 187 | "### Set Angle (range from 0 to 180)" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": null, 193 | "metadata": {}, 194 | "outputs": [], 195 | "source": [ 196 | "from time import sleep\n", 197 | "for angle in range(0, 180, 10):\n", 198 | " print(f\"{angle} degree\")\n", 199 | " servo.set_angular_position(angle)\n", 200 | " sleep(0.5)\n", 201 | "for angle in range(180, 0, -10):\n", 202 | " print(f\"{angle} degree\")\n", 203 | " servo.set_angular_position(angle)\n", 204 | " sleep(0.5)" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "Copyright (C) 2021 Xilinx, Inc\n", 212 | "\n", 213 | "SPDX-License-Identifier: BSD-3-Clause" 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": {}, 219 | "source": [ 220 | "----" 221 | ] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "----" 228 | ] 229 | } 230 | ], 231 | "metadata": { 232 | "kernelspec": { 233 | "display_name": "Python 3", 234 | "language": "python", 235 | "name": "python3" 236 | }, 237 | "language_info": { 238 | "codemirror_mode": { 239 | "name": "ipython", 240 | "version": 3 241 | }, 242 | "file_extension": ".py", 243 | "mimetype": "text/x-python", 244 | "name": "python", 245 | "nbconvert_exporter": "python", 246 | "pygments_lexer": "ipython3", 247 | "version": "3.6.5" 248 | } 249 | }, 250 | "nbformat": 4, 251 | "nbformat_minor": 4 252 | } 253 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_servo/src/grove_servo.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | #define DEVICE_MAX 4 37 | #define PERIOD 2000000 38 | #define DUTY_MIN 60000 39 | #define DUTY_MAX 235000 40 | #define ANGLE_MAX 180 41 | 42 | struct info { 43 | timer pin; 44 | int count; 45 | }; 46 | 47 | static struct info info[DEVICE_MAX]; 48 | 49 | /* 50 | * Documentation for public functions is provided as part of the external 51 | * public header file. 52 | * Documentation for static/private functions is provided above each 53 | * function in this file. 54 | */ 55 | 56 | /* Get next instance space 57 | * 58 | * Parameters 59 | * ---------- 60 | * None 61 | * 62 | * Return 63 | * ------ 64 | * int 65 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 66 | * 67 | */ 68 | static int next_index() { 69 | for (int i = 0; i < DEVICE_MAX; ++i) { 70 | if (info[i].count == 0) return i; 71 | } 72 | return -ENOMEM; 73 | } 74 | grove_servo grove_servo_open(int grove_id) { 75 | grove_servo dev_id = next_index(); 76 | if (dev_id >= 0) { 77 | info[dev_id].count++; 78 | info[dev_id].pin = timer_open_grove(grove_id); 79 | timer_pwm_generate(info[dev_id].pin, PERIOD, DUTY_MIN); 80 | } 81 | return dev_id; 82 | } 83 | 84 | void grove_servo_close(grove_servo p) { 85 | if (--info[p].count != 0) return; 86 | timer pin = info[p].pin; 87 | timer_pwm_stop(pin); 88 | timer_close(pin); 89 | } 90 | 91 | py_void grove_servo_set_angular_position(grove_servo p, float angle) { 92 | if (angle >=0 && angle <= 180) { 93 | timer pin = info[p].pin; 94 | int duty_cycle = DUTY_MIN + (angle/ANGLE_MAX) * (DUTY_MAX - DUTY_MIN); 95 | timer_pwm_generate(pin, PERIOD, duty_cycle); 96 | return PY_SUCCESS; 97 | } else { 98 | return -EPERM; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_temperature/include/grove_temperature.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // Device typedef 41 | 42 | /* Temperature class 43 | * 44 | * Available Methods: 45 | * open, close, get_temperature 46 | * 47 | * The open_adc is used when Grove_adc module is used to sample a signal 48 | * The open is used when System Monitor of the Zynq device used to sample a signal 49 | * 50 | */ 51 | typedef py_int grove_temperature; 52 | 53 | // Device lifetime functions 54 | /* Open a Temperature module connected directly to one of Arduino analog ports 55 | * or via a Grove ADC module (at default address) to an I2C port 56 | * 57 | * Parameters 58 | * ---------- 59 | * grove_id: int 60 | * Valid port ids for this device: 61 | * ARDUINO_SEEED_A0, ARDUINO_SEEED_A1, ARDUINO_SEEED_A2, ARDUINO_SEEED_A3 62 | * 63 | * Returns 64 | * ------- 65 | * grove_temperature 66 | * The device object if successful 67 | * -EIO device not present (raises exception) 68 | * -ENOMEM memory allocation error (raises exception) 69 | * 70 | */ 71 | grove_temperature grove_temperature_open(int grove_id); 72 | 73 | /* Open a temperature module connected to the specified port with the default 74 | * I2C address 75 | * 76 | * Parameters 77 | * ---------- 78 | * grove_id: int 79 | * Valid port ids for this device: 80 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 81 | * address: int 82 | * I2C address of the ADC 83 | * 84 | * Returns 85 | * ------- 86 | * grove_temperature 87 | * The device object if successful 88 | * -EIO device not present (raises exception) 89 | * -ENOMEM memory allocation error (raises exception) 90 | * 91 | */ 92 | grove_temperature grove_temperature_open_at_address(int grove_id, int address); 93 | 94 | /* Release the Grove Temperature by closing the device 95 | * 96 | * Parameters 97 | * ---------- 98 | * grove_id : int 99 | * The opened device object 100 | * 101 | * Returns 102 | * ------- 103 | * None 104 | * 105 | */ 106 | void grove_temperature_close(grove_temperature temp); 107 | 108 | // Device functions 109 | /* Read the connected device and return temperature in degree Celsius 110 | * 111 | * Parameters 112 | * ---------- 113 | * None 114 | * 115 | * Returns 116 | * ------- 117 | * float: 118 | * Temperature value in degree Celsius 119 | * NAN general operation error (raises exception) 120 | * 121 | */ 122 | py_float grove_temperature_get_temperature(grove_temperature temp); 123 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_temperature/src/grove_temperature.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | #define DEVICE_MAX 4 38 | 39 | struct info { 40 | analog pin; 41 | int count; 42 | }; 43 | 44 | static struct info info[DEVICE_MAX]; 45 | const int B = 4275; // B value of the thermistor 46 | const int R0 = 100000; // Resistance R0 = 100k 47 | 48 | /* 49 | * Documentation for public functions is provided as part of the external 50 | * public header file. 51 | * Documentation for static/private functions is provided above each 52 | * function in this file. 53 | */ 54 | 55 | /* Get next instance space 56 | * 57 | * Parameters 58 | * ---------- 59 | * None 60 | * 61 | * Return 62 | * ------ 63 | * int 64 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 65 | * 66 | */ 67 | static int next_index() { 68 | for (int i = 0; i < DEVICE_MAX; ++i) { 69 | if (info[i].count == 0) return i; 70 | } 71 | return -ENOMEM; 72 | } 73 | 74 | static grove_temperature grove_temperature_open_analog(analog pin) { 75 | grove_temperature dev_id = next_index(); 76 | if (dev_id >= 0) { 77 | info[dev_id].count++; 78 | info[dev_id].pin = pin; 79 | } 80 | return dev_id; 81 | } 82 | 83 | grove_temperature grove_temperature_open(int grove_id) { 84 | if (grove_id >= ARDUINO_DIGILENT_A1 && grove_id <= ARDUINO_SEEED_A3) 85 | return grove_temperature_open_analog(analog_open_grove(grove_id)); 86 | else 87 | return grove_temperature_open_analog(analog_open_grove_adc(grove_adc_open(grove_id))); 88 | 89 | } 90 | 91 | grove_temperature grove_temperature_open_at_address(int grove_id, int address) { 92 | return grove_temperature_open_analog(analog_open_grove_adc(grove_adc_open_at_address(grove_id, address))); 93 | 94 | } 95 | 96 | void grove_temperature_close(grove_temperature temp) { 97 | if (--info[temp].count != 0) return; 98 | analog pin = info[temp].pin; 99 | analog_close(pin); 100 | } 101 | 102 | py_float grove_temperature_get_temperature(grove_temperature temp) { 103 | analog pin = info[temp].pin; 104 | float R = (float)analog_get_max(pin) / (float)analog_get_raw(pin) - 1; 105 | R = R0 * R; 106 | float temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; 107 | return temperature; 108 | } 109 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_usranger/include/grove_usranger.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* usranger (UltraSonic distance finder) class 42 | * 43 | * Available Methods: 44 | * open, close, distance 45 | * 46 | */ 47 | typedef py_int grove_usranger; 48 | 49 | // Device lifetime functions 50 | /* Open a ultrasonic ranger device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_usranger 63 | * The device object if successful 64 | * -ENOMEM otherwise 65 | * 66 | */ 67 | grove_usranger grove_usranger_open(int grove_id); 68 | 69 | /* Release the ultrasonic ranger by closing the device 70 | * 71 | * Parameters 72 | * ---------- 73 | * None 74 | * 75 | * Returns 76 | * ------- 77 | * None 78 | * 79 | */ 80 | void grove_usranger_close(grove_usranger usranger); 81 | 82 | // Device functions 83 | /* Get distance in centimeters 84 | * 85 | * 86 | * Parameters 87 | * ---------- 88 | * None 89 | * 90 | * Returns 91 | * ------- 92 | * distance in centimeter: float 93 | * 94 | */ 95 | py_float grove_usranger_get_distance(grove_usranger usranger); 96 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_usranger/src/grove_usranger.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include "xparameters.h" 36 | #include "xtmrctr.h" 37 | #include "gpio.h" 38 | #include "timer.h" 39 | 40 | #define DEVICE_MAX 4 41 | #define MAX_COUNT 0xFFFFFFFF 42 | #define TIMEOUT 1e8 43 | 44 | struct info { 45 | gpio pin; 46 | int count; 47 | }; 48 | 49 | static struct info info[DEVICE_MAX]; 50 | 51 | /* 52 | * Documentation for public functions is provided as part of the external 53 | * public header file. 54 | * Documentation for static/private functions is provided above each 55 | * function in this file. 56 | */ 57 | 58 | /* Get next instance space 59 | * 60 | * Parameters 61 | * ---------- 62 | * None 63 | * 64 | * Return 65 | * ------ 66 | * int 67 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 68 | * 69 | */ 70 | static int next_index() { 71 | for (int i = 0; i < DEVICE_MAX; ++i) { 72 | if (info[i].count == 0) return i; 73 | } 74 | return -ENOMEM; 75 | } 76 | 77 | grove_usranger grove_usranger_open(int grove_id) { 78 | grove_usranger dev_id = next_index(); 79 | if (dev_id >= 0 ) { 80 | info[dev_id].count++; 81 | info[dev_id].pin = gpio_open_grove(grove_id); 82 | } 83 | return dev_id; 84 | } 85 | 86 | void grove_usranger_close(grove_usranger p) { 87 | if (--info[p].count != 0) return; 88 | gpio pin = info[p].pin; 89 | gpio_close(pin); 90 | } 91 | 92 | /* Generate a 10 us pulse 93 | * 94 | * Parameters 95 | * ---------- 96 | * None 97 | * 98 | * Return 99 | * ------ 100 | * None 101 | * 102 | */ 103 | static void create_10us_pulse(gpio pin){ 104 | gpio_set_direction(pin, GPIO_OUT); 105 | gpio_write(pin, 0); 106 | delay_us(2); 107 | gpio_write(pin, 1); 108 | delay_us(10); 109 | gpio_write(pin, 0); 110 | } 111 | 112 | /* Measure a pulse width 113 | * 114 | * Parameters 115 | * ---------- 116 | * None 117 | * 118 | * Return 119 | * ------ 120 | * pulse width: unsigned int 121 | * 122 | */ 123 | static unsigned int capture_duration(gpio pin){ 124 | unsigned int count0, count1, count2; 125 | count1 = 0; 126 | count2 = 0; 127 | XTmrCtr_WriteReg(XPAR_TMRCTR_0_BASEADDR, 0, TLR0, 0x0); 128 | XTmrCtr_WriteReg(XPAR_TMRCTR_0_BASEADDR, 0, TCSR0, 0x190); 129 | count0 = XTmrCtr_ReadReg(XPAR_TMRCTR_0_BASEADDR, 0, TCR0); 130 | count1=XTmrCtr_ReadReg(XPAR_TMRCTR_0_BASEADDR, 0, TCR0); 131 | while((!gpio_read(pin)) && ((count1 - count0) < TIMEOUT)) { 132 | count1=XTmrCtr_ReadReg(XPAR_TMRCTR_0_BASEADDR, 0, TCR0); 133 | } 134 | count2=XTmrCtr_ReadReg(XPAR_TMRCTR_0_BASEADDR, 0, TCR0); 135 | while(gpio_read(pin) && ((count2 - count1) < TIMEOUT)) { 136 | count2=XTmrCtr_ReadReg(XPAR_TMRCTR_0_BASEADDR, 0, TCR0); 137 | } 138 | 139 | if(count2 > count1) { 140 | return (count2 - count1); 141 | } else { 142 | return((MAX_COUNT - count1) + count2); 143 | } 144 | } 145 | 146 | py_float grove_usranger_get_distance(grove_usranger usranger) { 147 | gpio pin = info[usranger].pin; 148 | unsigned int raw_value; 149 | unsigned int num_nanoseconds; 150 | float distance_read; 151 | float max_distance = 5; // in meters 152 | int clk_period_ns = 10; 153 | float sound_speed = 340.29; 154 | 155 | create_10us_pulse(pin); 156 | gpio_set_direction(pin, GPIO_IN); 157 | raw_value = capture_duration(pin); 158 | num_nanoseconds = raw_value * clk_period_ns; 159 | distance_read = num_nanoseconds * 1e-9 * sound_speed / 2; 160 | if (distance_read > max_distance) { 161 | return max_distance * 100; 162 | } 163 | else { 164 | return distance_read * 100; 165 | } 166 | } -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_water_level/include/grove_water_level.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* Water level class 42 | * 43 | * Available Methods: 44 | * open, open_at_address, close, get_level 45 | * 46 | */ 47 | typedef py_int grove_water_level; 48 | 49 | // Device lifetime functions 50 | /* Open a water level module connected to the specified port with the default 51 | * I2C address 52 | * 53 | * Parameters 54 | * ---------- 55 | * grove_id: int 56 | * Valid port ids for this device: 57 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 58 | * 59 | * Returns 60 | * ------- 61 | * grove_water_level 62 | * The device object if successful 63 | * -EIO device not present (raises exception) 64 | * 65 | */ 66 | grove_water_level grove_water_level_open(int grove_id); 67 | 68 | /* Open a water level module connected to the specified port and a non-default 69 | * I2C address 70 | * 71 | * Unique I2C address is needed when two modules of same type are connected 72 | * to the same I2C channel. The two modules should have unique I2C 73 | * address 74 | * 75 | * Parameters 76 | * ---------- 77 | * grove_id: int 78 | * Valid port ids for this device: 79 | * PMOD_G3, PMOD_G4, ARDUINO_SEEED_I2C 80 | * address: integer 81 | * 82 | * Returns 83 | * ------- 84 | * grove_water_level 85 | * The device object if successful 86 | * -EIO device not present (raises exception) 87 | * 88 | */ 89 | grove_water_level grove_water_level_open_at_address(int grove_id, int address); 90 | 91 | /* Release the water level by closing the device 92 | * 93 | * Parameters 94 | * ---------- 95 | * None 96 | * 97 | * Returns 98 | * ------- 99 | * None 100 | * 101 | */ 102 | void grove_water_level_close(grove_water_level water_level); 103 | 104 | /* Get the water level value (the resolution is 0.5cm and the unit is cm) 105 | * 106 | * Parameters 107 | * ---------- 108 | * None 109 | * 110 | * Returns 111 | * ------- 112 | * float: 113 | * water level value (the resolution is 0.5cm and the unit is cm) 114 | * 115 | */ 116 | py_float grove_water_level_get_level(grove_water_level water_level); -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_water_level/src/grove_water_level.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #define I2C_ADDRESS_LO 0x77 40 | #define I2C_ADDRESS_HI 0x78 41 | #define THRESHOLD 100 42 | #define DEVICE_MAX 4 43 | 44 | struct info { 45 | i2c i2c_dev; 46 | unsigned char address; 47 | int count; 48 | }; 49 | 50 | static struct info info[DEVICE_MAX]; 51 | 52 | /* 53 | * Documentation for public functions is provided as part of the external 54 | * public header file. 55 | * Documentation for static/private functions is provided above each 56 | * function in this file. 57 | */ 58 | 59 | /* Get next instance space 60 | * 61 | * Parameters 62 | * ---------- 63 | * None 64 | * 65 | * Return 66 | * ------ 67 | * int 68 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 69 | * 70 | */ 71 | static int next_index() { 72 | for (int i = 0; i < DEVICE_MAX; ++i) { 73 | if (info[i].count == 0) return i; 74 | } 75 | return -ENOMEM; 76 | } 77 | 78 | /* Get the water level value 79 | * 80 | * Parameters 81 | * ---------- 82 | * None 83 | * 84 | * Return 85 | * ------ 86 | * float 87 | * The water level value in centimeter (the resolution is 0.5cm) 88 | * 89 | */ 90 | static float read_water_level(i2c device){ 91 | u8 data_buffer_lo[8]; 92 | u8 data_buffer_hi[12]; 93 | 94 | data_buffer_lo[0] = 0; 95 | if(i2c_write(device, I2C_ADDRESS_LO, data_buffer_lo, 1) != 1) return -EIO; 96 | if(i2c_read(device, I2C_ADDRESS_LO, data_buffer_lo, 8) != 8) return -EIO; 97 | 98 | data_buffer_hi[0] = 0; 99 | if(i2c_write(device, I2C_ADDRESS_HI, data_buffer_hi, 1) != 1) return -EIO; 100 | if(i2c_read(device, I2C_ADDRESS_HI, data_buffer_hi, 12) != 12) return -EIO; 101 | 102 | int i; 103 | for (i = 0; i < 8; i ++) 104 | { 105 | if (data_buffer_lo[i] < THRESHOLD) 106 | { 107 | return i * 0.5; 108 | } 109 | } 110 | for (i = 0; i < 12; i ++) 111 | { 112 | if (data_buffer_hi[i] < THRESHOLD) 113 | { 114 | return (i + 8) * 0.5; 115 | } 116 | } 117 | return 20 * 0.5; 118 | } 119 | 120 | grove_water_level grove_water_level_open(int grove_id) { 121 | return grove_water_level_open_at_address(grove_id, I2C_ADDRESS_LO); 122 | } 123 | 124 | grove_water_level grove_water_level_open_at_address(int grove_id, int address) { 125 | grove_water_level dev_id = next_index(); 126 | if (dev_id >=0 ) { 127 | info[dev_id].count++; 128 | info[dev_id].i2c_dev = i2c_open_grove(grove_id); 129 | info[dev_id].address = address; 130 | } 131 | return dev_id; 132 | } 133 | 134 | void grove_water_level_close(grove_water_level water_level) { 135 | if (--info[water_level].count != 0) return; 136 | i2c i2c_dev = info[water_level].i2c_dev; 137 | i2c_close(i2c_dev); 138 | } 139 | 140 | py_float grove_water_level_get_level(grove_water_level water_level) { 141 | return read_water_level(info[water_level].i2c_dev); 142 | } 143 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_water_sensor/include/grove_water_sensor.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | // Device typedef 40 | 41 | /* Water_sensor class 42 | * 43 | * Available Methods: 44 | * open, close, is_dry 45 | * 46 | */ 47 | typedef py_int grove_water_sensor; 48 | 49 | // Device lifetime functions 50 | /* Open a Water sensor device connected to the specified port 51 | * 52 | * Parameters 53 | * ---------- 54 | * grove_id: int 55 | * Valid port ids for this device: 56 | * PMOD_G1, PMOD_G2, PMOD_G3, PMOD_G4, ARDUINO_SEEED_D2, 57 | * ARDUINO_SEEED_D3,ARDUINO_SEEED_D4, ARDUINO_SEEED_D5, 58 | * ARDUINO_SEEED_D6, ARDUINO_SEEED_D7, ARDUINO_SEEED_D8 59 | * 60 | * Returns 61 | * ------- 62 | * grove_water 63 | * The device object 64 | * -ENOMEM if memory error 65 | * 66 | */ 67 | grove_water_sensor grove_water_sensor_open(int grove_id); 68 | 69 | /* Release the Water sensor by closing the device 70 | * 71 | * Parameters 72 | * ---------- 73 | * None 74 | * 75 | * Returns 76 | * ------- 77 | * None 78 | * 79 | */ 80 | void grove_water_sensor_close(grove_water_sensor water); 81 | 82 | // Device functions 83 | /* Sense if water is present 84 | * 85 | * Parameters 86 | * ---------- 87 | * None 88 | * 89 | * Returns 90 | * ------- 91 | * TRUE if dry 92 | * FALSE if wet 93 | * 94 | */ 95 | py_bool grove_water_sensor_is_dry(grove_water_sensor water); 96 | -------------------------------------------------------------------------------- /pynq_peripherals/modules/grove_water_sensor/src/grove_water_sensor.c: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * Copyright (c) 2021, Xilinx, Inc. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * 3. Neither the name of the copyright holder nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | * OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | *****************************************************************************/ 32 | 33 | #include 34 | #include 35 | 36 | #define DEVICE_MAX 4 37 | 38 | struct info { 39 | gpio pin; 40 | int count; 41 | }; 42 | 43 | static struct info info[DEVICE_MAX]; 44 | 45 | /* 46 | * Documentation for public functions is provided as part of the external 47 | * public header file. 48 | * Documentation for static/private functions is provided above each 49 | * function in this file. 50 | */ 51 | 52 | /* Get next instance space 53 | * 54 | * Parameters 55 | * ---------- 56 | * None 57 | * 58 | * Return 59 | * ------ 60 | * int 61 | * The next index. Return -12 (ENOMEM, no memory) if errors on read. 62 | * 63 | */ 64 | static int next_index() { 65 | for (int i = 0; i < DEVICE_MAX; ++i) { 66 | if (info[i].count == 0) return i; 67 | } 68 | return -ENOMEM; 69 | } 70 | 71 | grove_water_sensor grove_water_sensor_open(int grove_id) { 72 | grove_water_sensor dev_id = next_index(); 73 | if (dev_id >= 0) { 74 | info[dev_id].count++; 75 | info[dev_id].pin = gpio_open_grove(grove_id); 76 | gpio_set_direction(info[dev_id].pin, GPIO_IN); 77 | } 78 | return dev_id; 79 | } 80 | 81 | void grove_water_sensor_close(grove_water_sensor water) { 82 | if (--info[water].count != 0) return; 83 | gpio pin = info[water].pin; 84 | gpio_close(pin); 85 | } 86 | 87 | py_bool grove_water_sensor_is_dry(grove_water_sensor water) { 88 | gpio pin = info[water].pin; 89 | return gpio_read(pin); 90 | } 91 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021, Xilinx, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, 8 | # this list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 14 | # 3. Neither the name of the copyright holder nor the names of its 15 | # contributors may be used to endorse or promote products derived from 16 | # this software without specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | # OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | from distutils.dir_util import mkpath, copy_tree 31 | from distutils.file_util import copy_file 32 | from setuptools import setup, find_packages 33 | from setuptools.command.build_py import build_py as _build_py 34 | import glob 35 | import os 36 | 37 | 38 | class build_py(_build_py): 39 | def run(self): 40 | super().run() 41 | build_dir = self.data_files[0][2] 42 | notebook_mod_directories = glob.glob(build_dir + '/modules/*/notebooks') 43 | notebook_app_directories = glob.glob(build_dir + '/apps/*/notebooks') 44 | notebook_directories = notebook_mod_directories+notebook_app_directories 45 | mkpath(os.path.join(build_dir, 'notebooks')) 46 | for d in notebook_directories: 47 | module_name = os.path.basename(os.path.dirname(d)) 48 | copy_tree(d, os.path.join(build_dir, 'notebooks', module_name)) 49 | 50 | 51 | setup( 52 | name = "pynq_peripherals", 53 | version = "0.1.0", 54 | license = "BSD", 55 | author = "PYNQ Team", 56 | author_email = "pynq_support@xilinx.com", 57 | include_package_data = True, 58 | install_requires = ['pynq>=2.6.2', 'simple_term_menu'], 59 | entry_points = { 60 | 'pynq.lib': ['pynq_peripherals = pynq_peripherals'], 61 | 'pynq.notebooks': ['pynq_peripherals = pynq_peripherals.notebooks'], 62 | 'console_scripts': ['pynq-new-peripheral = pynq_peripherals.cli:main'] 63 | }, 64 | packages=find_packages(), 65 | cmdclass = { 66 | 'build_py': build_py 67 | }, 68 | description = "Driver packages for PYNQ Peripherals" 69 | ) 70 | --------------------------------------------------------------------------------