├── .gitignore ├── .vscode └── launch.json ├── 3rdparty └── popl │ ├── LICENSE │ └── README.md ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── COPYING.LESSER ├── README.md ├── cmake_uninstall.cmake.in ├── database ├── README.md ├── build ├── piduino-data-core.sql ├── piduino-data.sql ├── piduino-db-model.pdf ├── piduino-db-model.png ├── piduino-db-use_cases.md ├── piduino-pin-list.ods ├── piduino-rpi-list.ods ├── piduino-schema.sql ├── piduino.db ├── piduino.mwb └── piduino.ods ├── debian ├── postinst.in ├── postrm.in ├── preinst.in └── prerm.in ├── dev ├── CMakeLists.txt ├── bin │ ├── gdbasroot │ └── git-version ├── cmake │ ├── FindCPPDB.cmake │ ├── FindGZIP.cmake │ ├── GetDate.cmake │ └── GitVersion.cmake ├── codelite │ └── executable-piduino │ │ ├── executable-piduino.project │ │ ├── icon.png │ │ └── main.cpp └── libpiduino-dev.project ├── doc ├── CMakeLists.txt ├── Doxyfile.in ├── DoxygenLayout.xml ├── build_main_page.sh.in ├── images │ ├── PiduinoCommunityBanner.png │ ├── PiduinoCommunityBanner.svg │ ├── PiduinoCommunityLogo.svg │ ├── Piduino_Icon.svg │ ├── Piduino_Icon_small.png │ ├── Piduino_Logo.svg │ ├── chip.png │ ├── codelite-1.png │ ├── codelite-2.png │ ├── gplv3.png │ ├── lgplv3.png │ ├── osi.png │ └── vscode.png ├── libpiduino-doc.project ├── main_page_footer.dox └── main_page_header.dox ├── etc └── piduino.conf.in ├── examples ├── Blink-Daemon │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── Blinkd.project │ ├── Blinkd.workspace │ ├── CMakeLists.txt │ ├── README.md │ ├── bin │ │ └── gdbasroot │ ├── blinkd │ └── main.cpp ├── Blink │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── Blink.project │ ├── Blink.workspace │ ├── CMakeLists.txt │ ├── bin │ │ └── gdbasroot │ └── main.cpp ├── Button │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── Button.project │ ├── Button.workspace │ ├── CMakeLists.txt │ ├── bin │ │ └── gdbasroot │ └── main.cpp ├── CMakeLists.txt ├── Communication │ ├── ASCIITable │ │ ├── ASCIITable.project │ │ ├── ASCIITable.workspace │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── CMakeLists.txt │ ├── Console │ │ ├── CMakeLists.txt │ │ ├── Console.project │ │ ├── Console.workspace │ │ └── main.cpp │ ├── ReadASCIIString │ │ ├── CMakeLists.txt │ │ ├── ReadASCIIString.project │ │ ├── ReadASCIIString.workspace │ │ └── main.cpp │ ├── SerialPing │ │ ├── CMakeLists.txt │ │ ├── SerialPing.project │ │ ├── SerialPing.workspace │ │ └── main.cpp │ ├── SerialPong │ │ ├── CMakeLists.txt │ │ ├── SerialPong.project │ │ ├── SerialPong.workspace │ │ └── main.cpp │ └── SerialPrint │ │ ├── CMakeLists.txt │ │ ├── SerialPrint.project │ │ ├── SerialPrint.workspace │ │ └── main.cpp ├── Fade │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── CMakeLists.txt │ ├── Fade.project │ ├── Fade.workspace │ ├── bin │ │ └── gdbasroot │ └── main.cpp ├── Interrupt │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── CMakeLists.txt │ ├── Interrupt.project │ ├── Interrupt.workspace │ ├── bin │ │ └── gdbasroot │ └── main.cpp ├── NoArduino │ ├── CMakeLists.txt │ ├── Gpio │ │ ├── Blink │ │ │ ├── .gitignore │ │ │ ├── .vscode │ │ │ │ └── launch.json │ │ │ ├── Blink.project │ │ │ ├── Blink.workspace │ │ │ ├── CMakeLists.txt │ │ │ ├── bin │ │ │ │ └── gdbasroot │ │ │ └── main.cpp │ │ ├── CMakeLists.txt │ │ ├── Fade │ │ │ ├── .gitignore │ │ │ ├── .vscode │ │ │ │ └── launch.json │ │ │ ├── CMakeLists.txt │ │ │ ├── Fade.project │ │ │ ├── Fade.workspace │ │ │ ├── bin │ │ │ │ └── gdbasroot │ │ │ └── main.cpp │ │ ├── Interrupt │ │ │ ├── .gitignore │ │ │ ├── .vscode │ │ │ │ └── launch.json │ │ │ ├── CMakeLists.txt │ │ │ ├── Interrupt.project │ │ │ ├── Interrupt.workspace │ │ │ ├── bin │ │ │ │ └── gdbasroot │ │ │ └── main.cpp │ │ └── WaitForInt │ │ │ ├── .gitignore │ │ │ ├── .vscode │ │ │ └── launch.json │ │ │ ├── CMakeLists.txt │ │ │ ├── WaitForInt.project │ │ │ ├── WaitForInt.workspace │ │ │ ├── bin │ │ │ └── gdbasroot │ │ │ └── main.cpp │ └── piduino-examples.workspace ├── Spi │ ├── CMakeLists.txt │ ├── SpiMemoryMb85rs │ │ ├── .gitignore │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── SpiMemoryMb85rs.project │ │ ├── SpiMemoryMb85rs.workspace │ │ ├── bin │ │ │ └── gdbasroot │ │ ├── main.cpp │ │ ├── mb85rs.cpp │ │ └── mb85rs.h │ └── SpiPressureSensorHsc │ │ ├── .gitignore │ │ ├── .vscode │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── SpiPressureSensorHsc.project │ │ ├── SpiPressureSensorHsc.workspace │ │ ├── bin │ │ └── gdbasroot │ │ └── main.cpp ├── Template │ ├── .gitignore │ ├── .vscode │ │ └── launch.json │ ├── CMakeLists.txt │ ├── README.md │ ├── Template.project │ ├── bin │ │ └── gdbasroot │ └── main.cpp ├── Wire │ ├── CMakeLists.txt │ ├── WireDigitalPotentiometer │ │ ├── .gitignore │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── WireDigitalPotentiometer.project │ │ ├── WireDigitalPotentiometer.workspace │ │ ├── bin │ │ │ └── gdbasroot │ │ └── main.cpp │ ├── WireMasterReader │ │ ├── .gitignore │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── WireMasterReader.project │ │ ├── WireMasterReader.workspace │ │ ├── bin │ │ │ └── gdbasroot │ │ └── main.cpp │ ├── WireMasterWriter │ │ ├── .gitignore │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── WireMasterWriter.project │ │ ├── WireMasterWriter.workspace │ │ ├── bin │ │ │ └── gdbasroot │ │ └── main.cpp │ └── WireRtcBq32k │ │ ├── .gitignore │ │ ├── .vscode │ │ └── launch.json │ │ ├── CMakeLists.txt │ │ ├── WireRtcBq32k.project │ │ ├── WireRtcBq32k.workspace │ │ ├── bin │ │ └── gdbasroot │ │ └── main.cpp ├── arduino-examples.workspace └── vscode-sudo.tar.gz ├── include └── piduino │ ├── arduino │ ├── Arduino.h │ ├── Client.h │ ├── Console.h │ ├── HardwareSerial.h │ ├── IPAddress.h │ ├── Piduino.h │ ├── Print.h │ ├── Printable.h │ ├── SPI.h │ ├── Server.h │ ├── Stream.h │ ├── Terminal.h │ ├── WCharacter.h │ ├── WString.h │ ├── Wire.h │ ├── binary.h │ └── pgmspace.h │ ├── board.h │ ├── clock.h │ ├── configfile.h │ ├── converter.h │ ├── database.h │ ├── fifo.h │ ├── filedevice.h │ ├── fileno.h │ ├── filestream.h │ ├── flags.h │ ├── global.h │ ├── gpio.h │ ├── gpioconnector.h │ ├── gpiodevice.h │ ├── gpiopin.h │ ├── gpiopwm.h │ ├── i2cdev.h │ ├── iodevice.h │ ├── iomap.h │ ├── linearbuffer.h │ ├── manufacturer.h │ ├── memory.h │ ├── popl.h │ ├── pwm.h │ ├── ringbuffer.h │ ├── scheduler.h │ ├── serialport.h │ ├── soc.h │ ├── socpwm.h │ ├── spidev.h │ ├── string.h │ ├── syslog.h │ ├── system.h │ ├── terminal.h │ ├── terminalnotifier.h │ └── threadsafebuffer.h ├── lib ├── CMakeLists.txt ├── config.h.in ├── piduino-config-version.cmake.in ├── piduino-config.cmake.in └── piduino.pc.in ├── libpiduino.project ├── piduino.workspace ├── src ├── arch │ └── arm │ │ ├── allwinner │ │ ├── gpio_hx.cpp │ │ ├── gpio_hx.h │ │ ├── gpio_hx_p.h │ │ ├── hx.h │ │ ├── pwm_hx.cpp │ │ └── pwm_hx.h │ │ └── broadcom │ │ ├── bcm2835.cpp │ │ ├── bcm2835.h │ │ ├── gpio_bcm2835.cpp │ │ ├── gpio_bcm2835.h │ │ ├── gpio_bcm2835_p.h │ │ ├── pwm_bcm2835.cpp │ │ └── pwm_bcm2835.h ├── arduino │ ├── Console.cpp │ ├── Core.cpp │ ├── IPAddress.cpp │ ├── Print.cpp │ ├── Stream.cpp │ ├── Terminal.cpp │ ├── WMath.cpp │ ├── compat │ │ └── strlcat_strlcpy.c │ ├── i2c │ │ └── Wire.cpp │ ├── serial │ │ └── HardwareSerial.cpp │ └── spi │ │ └── SPI.cpp ├── board.cpp ├── clock.cpp ├── converter.cpp ├── converter_p.h ├── database.cpp ├── dummy.cpp ├── filedevice.cpp ├── filedevice_p.h ├── fileno.cpp ├── filestream.cpp ├── filestream_p.h ├── gpio │ ├── gpio-database.cpp │ ├── gpio.cpp │ ├── gpio_p.h │ ├── gpioconnector-database.cpp │ ├── gpioconnector.cpp │ ├── gpioconnector_p.h │ ├── gpiodevice.cpp │ ├── gpiodevice_p.h │ ├── gpiopin-database.cpp │ ├── gpiopin.cpp │ ├── gpiopin_p.cpp │ ├── gpiopin_p.h │ ├── gpiopwm.cpp │ ├── gpiopwm_p.h │ ├── socpwm.cpp │ └── socpwm_p.h ├── i2c │ ├── i2cdev.cpp │ └── i2cdev_p.h ├── iodevice.cpp ├── iodevice_p.h ├── iomap.cpp ├── manufacturer.cpp ├── piduino.cpp ├── pwm.cpp ├── pwm_p.h ├── scheduler.cpp ├── serial │ ├── serialport.cpp │ ├── serialport_p.h │ ├── serialportinfo.cpp │ └── serialportinfo_p.h ├── soc.cpp ├── spi │ ├── spidev.cpp │ └── spidev_p.h ├── string.cpp ├── syslog.cpp ├── system.cpp ├── terminal.cpp ├── terminal_p.h ├── terminalnotifier.cpp └── terminalnotifier_p.h └── utils ├── CMakeLists.txt ├── pido ├── CMakeLists.txt ├── exception.cpp ├── exception.h ├── main.cpp ├── pido.1.in ├── pido.project └── pido.workspace ├── piduino-utils.project ├── piduino-utils.workspace └── pinfo ├── CMakeLists.txt ├── main.cpp ├── pinfo.1.in ├── pinfo.project └── pinfo.workspace /.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Debug as root", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | "readall" 12 | ], 13 | "stopAtEntry": true, 14 | "cwd": "${workspaceFolder}", 15 | "environment": [ 16 | { 17 | // add the directory where our target was built to the PATHs 18 | // it gets resolved by CMake Tools: 19 | "name": "PATH", 20 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 21 | } 22 | ], 23 | "externalConsole": false, 24 | "miDebuggerPath": "${workspaceFolder}/dev/bin/gdbasroot", 25 | "MIMode": "gdb", 26 | "setupCommands": [ 27 | { 28 | "description": "Enable pretty-printing for gdb", 29 | "text": "-enable-pretty-printing", 30 | "ignoreFailures": true 31 | } 32 | ] 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /3rdparty/popl/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015-2016 Johannes Pohl 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | * Pascal JEAN piduino.org> 2 | -------------------------------------------------------------------------------- /database/README.md: -------------------------------------------------------------------------------- 1 | # piduino-database 2 | Arduino on Pi boards, the best of both worlds ! 3 | 4 | Piduino uses a relational database which ensures very good 5 | data integrity and avoids redundancies. 6 | 7 | | ![db model](piduino-db-model.png) | 8 | |:--:| 9 | | *Piduino Relational Database Model* | 10 | 11 | ## import depuis sql 12 | 13 | sqlite3 < piduino-schema.sql 14 | sqlite3 piduino.db < piduino-data.sql 15 | 16 | ## export schema vers sql 17 | 18 | .output schema.sql 19 | .schema 20 | 21 | ## export data vers sql 22 | 23 | echo "BEGIN TRANSACTION;" > piduino-data.sql; sqlite3 piduino.db .dump | grep '^INSERT INTO' | grep -v 'sqlite_sequence' >> piduino-data.sql; echo "COMMIT;" >> piduino-data.sql 24 | 25 | ## export table vers sql de données 26 | 27 | .mode insert 28 | .output data.sql 29 | select * from board; 30 | 31 | ## export vers csv de données 32 | 33 | .mode csv 34 | .header on 35 | .output data.csv 36 | select * from board; 37 | 38 | ## export depuis MySQL Workbench 39 | 40 | https://github.com/tatsushid/mysql-wb-exportsqlite 41 | 42 | puis 43 | 44 | sed -i -e '/^CREATE\ INDEX/d' piduino-schema.sql 45 | sed -i -e 's/piduino\.sdb/piduino\.db/g' piduino-schema.sql 46 | 47 | ExportSQLite is a plugin for 48 | [MySQL Workbench](http://www.mysql.com/products/workbench/) to export a schema 49 | catalog as SQLite's CREATE SQL queries. This is a Python port of 50 | [original Lua script](https://gist.github.com/mrprompt/7252060) for using with 51 | MySQL Workbench 6.2 or above. 52 | 53 | ### Installation 54 | 55 | 1. Open MySQL Workbench 56 | 2. Choose "Install Plugin/Module..." in "Scripting" menu 57 | 3. Open `export_sqlite_grt.py` file 58 | 4. Restart MySQL Workbench 59 | 60 | ### Usage 61 | 62 | Once you open a database model in MySQL Workbench, you can see "Export SQLite 63 | CREATE script" in "Tools > Catalog" menu. Just choose it. 64 | 65 | -------------------------------------------------------------------------------- /database/build: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | rm -f piduino.db 4 | sed -i -e '/^CREATE\ INDEX/d' piduino-schema.sql 5 | sed -i -e 's/piduino\.sdb/piduino\.db/g' piduino-schema.sql 6 | sqlite3 < piduino-schema.sql 7 | sqlite3 piduino.db < piduino-data.sql 8 | -------------------------------------------------------------------------------- /database/piduino-data-core.sql: -------------------------------------------------------------------------------- 1 | BEGIN TRANSACTION; 2 | INSERT INTO "pin_mode" VALUES(0,'Input'); 3 | INSERT INTO "pin_mode" VALUES(1,'Output'); 4 | INSERT INTO "pin_mode" VALUES(2,'Disabled'); 5 | INSERT INTO "pin_mode" VALUES(3,'Pwm'); 6 | INSERT INTO "pin_mode" VALUES(4,'Alt0'); 7 | INSERT INTO "pin_mode" VALUES(5,'Alt1'); 8 | INSERT INTO "pin_mode" VALUES(6,'Alt2'); 9 | INSERT INTO "pin_mode" VALUES(7,'Alt3'); 10 | INSERT INTO "pin_mode" VALUES(8,'Alt4'); 11 | INSERT INTO "pin_mode" VALUES(9,'Alt5'); 12 | INSERT INTO "pin_mode" VALUES(10,'Alt6'); 13 | INSERT INTO "pin_mode" VALUES(11,'Alt7'); 14 | INSERT INTO "pin_mode" VALUES(12,'Alt8'); 15 | INSERT INTO "pin_mode" VALUES(13,'Alt9'); 16 | INSERT INTO "pin_type" VALUES(0,'Gpio'); 17 | INSERT INTO "pin_type" VALUES(1,'Power'); 18 | INSERT INTO "pin_type" VALUES(2,'Usb'); 19 | INSERT INTO "pin_type" VALUES(3,'Sound'); 20 | INSERT INTO "pin_type" VALUES(4,'Video'); 21 | INSERT INTO "pin_type" VALUES(5,'Not Connected'); 22 | INSERT INTO "pin_type" VALUES(6,'Net'); 23 | INSERT INTO "schema_version" VALUES(1,'2018-10-22 08:49:51','2018-10-23 09:46:59',0,3,1); 24 | INSERT INTO "schema_version" VALUES(2,'2018-10-23 09:47:00',NULL,0,3,2); 25 | INSERT INTO "board_family" VALUES(-1,'Unknown',NULL,NULL,NULL); 26 | INSERT INTO "board_family" VALUES(0,'RaspberryPi','/dev/i2c-%d','/dev/spidev%d.%d','/dev/ttyAMA%d'); 27 | INSERT INTO "board_family" VALUES(1,'NanoPi','/dev/i2c-%d','/dev/spidev%d.%d','/dev/ttyS%d'); 28 | INSERT INTO "board_family" VALUES(2,'OrangePi','/dev/i2c-%d','/dev/spidev%d.%d','/dev/ttyS%d'); 29 | INSERT INTO "board_family" VALUES(3,'BananaPi','/dev/i2c-%d','/dev/spidev%d.%d','/dev/ttyS%d'); 30 | INSERT INTO "arch" VALUES(-1,'Unknown'); 31 | INSERT INTO "arch" VALUES(0,'ARM'); 32 | INSERT INTO "manufacturer" VALUES(-1,'Unknown'); 33 | INSERT INTO "manufacturer" VALUES(0,'Broadcom'); 34 | INSERT INTO "manufacturer" VALUES(1,'Sony'); 35 | INSERT INTO "manufacturer" VALUES(2,'Qisda'); 36 | INSERT INTO "manufacturer" VALUES(3,'Egoman'); 37 | INSERT INTO "manufacturer" VALUES(4,'Embest'); 38 | INSERT INTO "manufacturer" VALUES(5,'Allwinner'); 39 | INSERT INTO "manufacturer" VALUES(6,'Friendly ARM'); 40 | INSERT INTO "manufacturer" VALUES(7,'Stadium'); 41 | INSERT INTO "connector_family" VALUES(0,'Header1X',1); 42 | INSERT INTO "connector_family" VALUES(1,'Header2X',2); 43 | INSERT INTO "soc_family" VALUES(-1,'Unknown',-1); 44 | INSERT INTO "soc_family" VALUES(0,'Bcm283x',0); 45 | INSERT INTO "soc_family" VALUES(1,'H-Series',0); 46 | COMMIT; 47 | -------------------------------------------------------------------------------- /database/piduino-db-model.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino-db-model.pdf -------------------------------------------------------------------------------- /database/piduino-db-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino-db-model.png -------------------------------------------------------------------------------- /database/piduino-pin-list.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino-pin-list.ods -------------------------------------------------------------------------------- /database/piduino-rpi-list.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino-rpi-list.ods -------------------------------------------------------------------------------- /database/piduino.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino.db -------------------------------------------------------------------------------- /database/piduino.mwb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino.mwb -------------------------------------------------------------------------------- /database/piduino.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/database/piduino.ods -------------------------------------------------------------------------------- /debian/postinst.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Filename: postinst 3 | # Purpose: postinst script for package libpiduino 4 | # Authors: Copyright © 2018-2025 Pascal JEAN, All rights reserved. 5 | # Bug-Reports: https://github.com/epsilonrt/piduino/issues 6 | # SPDX-License-Identifier: LGPL-3.0-or-later 7 | set -e 8 | 9 | PIDUINO_CONF_FILE=@PIDUINO_INSTALL_ETC_DIR@/piduino.conf 10 | 11 | echo "Running postinst($1) script for package libpiduino..." 12 | 13 | case "$1" in 14 | install|upgrade|configure) 15 | # echo "Checking if file '$PIDUINO_CONF_FILE.dpkg-dist' exists..." 16 | 17 | if [ -e "$PIDUINO_CONF_FILE.dpkg-dist" ]; then 18 | mv -f "$PIDUINO_CONF_FILE.dpkg-dist" "$PIDUINO_CONF_FILE" && echo "File '$PIDUINO_CONF_FILE' restored from backup '$PIDUINO_CONF_FILE.dpkg-dist'." 19 | fi 20 | ;; 21 | *) 22 | echo "postinst called with unknown argument $1" >&2 23 | exit 1 24 | esac 25 | 26 | exit 0 -------------------------------------------------------------------------------- /debian/postrm.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Filename: postrm 3 | # Purpose: postrm script for package libpiduino 4 | # Authors: Copyright © 2018-2025 Pascal JEAN, All rights reserved. 5 | # Bug-Reports: https://github.com/epsilonrt/piduino/issues 6 | # SPDX-License-Identifier: LGPL-3.0-or-later 7 | set -e 8 | 9 | PIDUINO_CONF_FILE=@PIDUINO_INSTALL_ETC_DIR@/piduino.conf 10 | 11 | echo "Running postrm($1) script for package libpiduino..." 12 | 13 | case "$1" in 14 | purge) 15 | rm -f "$PIDUINO_CONF_FILE" "$PIDUINO_CONF_FILE.dpkg-dist" "$PIDUINO_CONF_FILE.dpkg-old" && echo "File '$PIDUINO_CONF_FILE' and its backups have been removed." 16 | ;; 17 | upgrade|failed-upgrade|abort-install|abort-upgrade|disappear|remove) 18 | ;; 19 | *) 20 | echo "postrm called with unknown argument $1" >&2 21 | exit 1 22 | esac 23 | 24 | exit 0 -------------------------------------------------------------------------------- /debian/preinst.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Filename: preinst 3 | # Purpose: preinst script for package libpiduino 4 | # Authors: Copyright © 2018-2025 Pascal JEAN, All rights reserved. 5 | # Bug-Reports: https://github.com/epsilonrt/piduino/issues 6 | # SPDX-License-Identifier: LGPL-3.0-or-later 7 | set -e 8 | 9 | PIDUINO_CONF_FILE=@PIDUINO_INSTALL_ETC_DIR@/piduino.conf 10 | 11 | echo "Running preinst($1) script for package libpiduino..." 12 | 13 | case "$1" in 14 | install|upgrade|configure) 15 | 16 | # echo "Checking if file '$PIDUINO_CONF_FILE' exists..." 17 | if [ -e "$PIDUINO_CONF_FILE" ]; then 18 | read -p "File '$PIDUINO_CONF_FILE' exists. Overwrite? (y/N): " answer 19 | case "$answer" in 20 | [Yy]* ) 21 | cp -f "$PIDUINO_CONF_FILE" "$PIDUINO_CONF_FILE".dpkg-old && echo "File '$PIDUINO_CONF_FILE' has been backed up as '$PIDUINO_CONF_FILE.dpkg-old'." 22 | ;; 23 | * ) 24 | cp -n "$PIDUINO_CONF_FILE" "$PIDUINO_CONF_FILE".dpkg-dist && echo "File '$PIDUINO_CONF_FILE' not overwritten. A backup has been created as '$PIDUINO_CONF_FILE.dpkg-dist'." 25 | ;; 26 | esac 27 | fi 28 | ;; 29 | *) 30 | echo "preinst called with unknown argument $1" >&2 31 | exit 1 32 | esac 33 | 34 | exit 0 -------------------------------------------------------------------------------- /debian/prerm.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Filename: prerm 3 | # Purpose: prerm script for package libpiduino 4 | # Authors: Copyright © 2018-2025 Pascal JEAN, All rights reserved. 5 | # Bug-Reports: https://github.com/epsilonrt/piduino/issues 6 | # SPDX-License-Identifier: LGPL-3.0-or-later 7 | set -e 8 | 9 | PIDUINO_CONF_FILE=@PIDUINO_INSTALL_ETC_DIR@/piduino.conf 10 | 11 | echo "Running prerm($1) script for package libpiduino..." 12 | 13 | case "$1" in 14 | purge) 15 | rm -f "$PIDUINO_CONF_FILE" "$PIDUINO_CONF_FILE.dpkg-dist" && echo "File '$PIDUINO_CONF_FILE' and its backup '$PIDUINO_CONF_FILE.dpkg-dist' have been removed." 16 | ;; 17 | upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) 18 | ;; 19 | remove) 20 | if [ -e "$PIDUINO_CONF_FILE" ]; then 21 | cp -n "$PIDUINO_CONF_FILE" "$PIDUINO_CONF_FILE".dpkg-dist && echo "File '$PIDUINO_CONF_FILE' has been backed up as '$PIDUINO_CONF_FILE.dpkg-dist'." 22 | fi 23 | ;; 24 | *) 25 | echo "prerm called with unknown argument $1" >&2 26 | exit 1 27 | esac 28 | 29 | exit 0 -------------------------------------------------------------------------------- /dev/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Pascal JEAN, All rights reserved. 2 | # This file is part of the Piduino Project. 3 | # 4 | # The Piduino Project is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # The Piduino Project is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with the Piduino Project. If not, see . 16 | # piduino/dev CMakeLists.txt 17 | 18 | cmake_minimum_required(VERSION 3.0) 19 | 20 | # set packaging dir 21 | if(NOT CPACK_PACKAGE_DIRECTORY) 22 | set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages) 23 | endif() 24 | 25 | if("${CMAKE_PROJECT_NAME}" STREQUAL "Project") 26 | set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) 27 | endif() 28 | 29 | 30 | file(GLOB dev_cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/*.cmake) 31 | 32 | install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/bin/git-version 33 | DESTINATION "${INSTALL_BIN_DIR}" 34 | PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ 35 | WORLD_EXECUTE WORLD_READ 36 | COMPONENT dev 37 | ) 38 | 39 | install (FILES ${dev_cmake} 40 | DESTINATION "${PIDUINO_INSTALL_CMAKE_DIR}" 41 | PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ 42 | COMPONENT dev 43 | ) 44 | 45 | install (DIRECTORY codelite/executable-piduino 46 | DESTINATION "${INSTALL_CODELITE_DIR}/templates/projects" 47 | DIRECTORY_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ 48 | COMPONENT dev 49 | FILES_MATCHING 50 | PATTERN "*" 51 | PATTERN "Debug" EXCLUDE 52 | PATTERN "Release" EXCLUDE 53 | PATTERN "*.mk" EXCLUDE 54 | PATTERN "*.txt" EXCLUDE 55 | PATTERN ".clang" EXCLUDE 56 | PATTERN ".codelite" EXCLUDE) 57 | 58 | # Examples 59 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/examples/ 60 | DESTINATION ${PIDUINO_INSTALL_EXAMPLES_DIR} 61 | COMPONENT dev 62 | FILES_MATCHING 63 | PATTERN "*.c" 64 | PATTERN "*.cpp" 65 | PATTERN "*.h" 66 | PATTERN "*.project" 67 | PATTERN "*.workspace" 68 | PATTERN "Debug" EXCLUDE 69 | PATTERN "Release" EXCLUDE 70 | PATTERN "*.mk" EXCLUDE 71 | PATTERN "*.txt" EXCLUDE 72 | PATTERN ".clang" EXCLUDE 73 | PATTERN ".codelite" EXCLUDE 74 | PATTERN "cmake-build*" EXCLUDE) 75 | 76 | -------------------------------------------------------------------------------- /dev/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /dev/cmake/FindCPPDB.cmake: -------------------------------------------------------------------------------- 1 | # Find the CppDb includes and library 2 | # 3 | # This module defines 4 | # CPPDB_INCLUDE_DIRS - include directories for cppdb 5 | # CPPDB_LIBRARY_DIRS - where to find libraries 6 | # CPPDB_LIBRARIES - libraries to link against 7 | 8 | find_path(CPPDB_INCLUDE_DIRS cppdb/frontend.h) 9 | 10 | find_library(CPPDB_LIBRARIES cppdb) 11 | 12 | if(CPPDB_INCLUDE_DIRS) 13 | if(CPPDB_LIBRARIES) 14 | get_filename_component(CPPDB_LIBRARY_DIRS ${CPPDB_LIBRARIES} PATH) 15 | set(CPPDB_FOUND TRUE) 16 | set(CPPDB_LIBRARIES cppdb ${CMAKE_DL_LIBS}) 17 | set(CPPDB_LDFLAGS -lcppdb -l${CMAKE_DL_LIBS}) 18 | endif(CPPDB_LIBRARIES) 19 | endif(CPPDB_INCLUDE_DIRS) 20 | 21 | include(FindPackageHandleStandardArgs) 22 | find_package_handle_standard_args(CPPDB DEFAULT_MSG CPPDB_LIBRARIES CPPDB_INCLUDE_DIRS) 23 | 24 | #message(STATUS "CPPDB_INCLUDE_DIRS=${CPPDB_INCLUDE_DIRS}") 25 | #message(STATUS "CPPDB_LIBRARIES=${CPPDB_LIBRARIES}") 26 | #message(STATUS "CPPDB_LIBRARY_DIRS=${CPPDB_LIBRARY_DIRS}") 27 | -------------------------------------------------------------------------------- /dev/cmake/FindGZIP.cmake: -------------------------------------------------------------------------------- 1 | # Find gzip 2 | # Export variables: 3 | # GZIP_FOUND 4 | # GZIP_EXE 5 | 6 | find_program(GZIP_EXE gzip) 7 | 8 | include(FindPackageHandleStandardArgs) 9 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( GZIP DEFAULT_MSG GZIP_EXE ) 10 | mark_as_advanced(GZIP_EXE) 11 | 12 | macro(gzip_compress target_name input_files result_archive) 13 | add_custom_command( 14 | OUTPUT ${result_archive} 15 | COMMAND ${GZIP_EXE} --best --to-stdout ${input_files} > ${result_archive} 16 | COMMENT "Compressing ${input_files}" 17 | DEPENDS ${input_files} ${ARGN} 18 | ) 19 | add_custom_target(${target_name} ALL DEPENDS ${result_archive}) 20 | endmacro() 21 | -------------------------------------------------------------------------------- /dev/codelite/executable-piduino/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/dev/codelite/executable-piduino/icon.png -------------------------------------------------------------------------------- /dev/codelite/executable-piduino/main.cpp: -------------------------------------------------------------------------------- 1 | // Blink 2 | 3 | // Turns an LED on for one second, then off for one second, repeatedly. 4 | 5 | // Created 8 March 2018 6 | 7 | // This example code is in the public domain. 8 | #ifdef __unix__ 9 | #include // All the magic is here ;-) 10 | #else 11 | // Defines the serial port as the console on the Arduino platform 12 | #define Console Serial 13 | #endif 14 | 15 | // Be careful !!! Before launching this program : 16 | // -> Check that the pin below is well connected to an LED ! <- 17 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 18 | 19 | void setup() { 20 | // initialize digital pin ledPin as an output. 21 | pinMode (ledPin, OUTPUT); 22 | } 23 | 24 | void loop () { 25 | // Press Ctrl+C to abort ... 26 | digitalWrite (ledPin, HIGH); // turn the LED on (HIGH is the voltage level) 27 | delay (1000); // wait for a second 28 | digitalWrite (ledPin, LOW); // turn the LED off by making the voltage LOW 29 | delay (1000); // wait for a second 30 | } 31 | -------------------------------------------------------------------------------- /doc/build_main_page.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # (c) Copyright 2011-2016 Pascal JEAN, All rights reserved. 3 | # Licensed under the Apache License, Version 2.0 (the "License") 4 | 5 | TARGET=@DOXYGEN_MAINPAGE@ 6 | README=@DOXYGEN_README@ 7 | 8 | PARSER=cat 9 | command -v marked >/dev/null 2>&1 && PARSER=marked 10 | # echo "PARSER=$PARSER" 11 | if [ "$PARSER" = "marked" ]; then 12 | HEAD_TAG="@htmlonly" 13 | FOOT_TAG="@endhtmlonly" 14 | fi 15 | 16 | cat @PROJECT_SOURCE_DIR@/doc/main_page_header.dox > $TARGET 17 | 18 | # README 19 | echo "$HEAD_TAG" >> $TARGET 20 | tail -n +4 $README | ${PARSER} >> $TARGET 21 | echo "$FOOT_TAG" >> $TARGET 22 | 23 | cat @PROJECT_SOURCE_DIR@/doc/main_page_footer.dox >> $TARGET 24 | -------------------------------------------------------------------------------- /doc/images/PiduinoCommunityBanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/PiduinoCommunityBanner.png -------------------------------------------------------------------------------- /doc/images/Piduino_Icon_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/Piduino_Icon_small.png -------------------------------------------------------------------------------- /doc/images/chip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/chip.png -------------------------------------------------------------------------------- /doc/images/codelite-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/codelite-1.png -------------------------------------------------------------------------------- /doc/images/codelite-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/codelite-2.png -------------------------------------------------------------------------------- /doc/images/gplv3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/gplv3.png -------------------------------------------------------------------------------- /doc/images/lgplv3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/lgplv3.png -------------------------------------------------------------------------------- /doc/images/osi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/osi.png -------------------------------------------------------------------------------- /doc/images/vscode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/doc/images/vscode.png -------------------------------------------------------------------------------- /doc/main_page_footer.dox: -------------------------------------------------------------------------------- 1 | 2 | */ 3 | -------------------------------------------------------------------------------- /doc/main_page_header.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @file 3 | @brief Page de garde de la documentation 4 | @author Pascal JEAN. Copyright © 2015-2017 All rights reserved. 5 | 6 | @mainpage Présentation 7 | -------------------------------------------------------------------------------- /etc/piduino.conf.in: -------------------------------------------------------------------------------- 1 | # PiDuino configuration file 2 | connection_info="sqlite3:db=@PIDUINO_INSTALL_DATA_DIR@/piduino.db" 3 | 4 | # Allows you to force the board tag (Armbian) 5 | # !! Be careful, this is at your own risk !! 6 | # !! Forcing an incorrect value may destroy GPIO pins !! 7 | #tag="nanopineocore" 8 | 9 | # Allows forcing the revision of the board (Raspbian) 10 | # !! Be careful, this is at your own risk !! 11 | # !! Forcing an incorrect value may destroy GPIO pins !! 12 | #revision=0xa02082 13 | -------------------------------------------------------------------------------- /examples/Blink-Daemon/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Blink-Daemon/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Blink-Daemon/Blinkd.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Blink-Daemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Blinkd) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Blink-Daemon/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Blink-Daemon/blinkd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | ### BEGIN INIT INFO 4 | # Provides: blinkd 5 | # Required-Start: $remote_fs $syslog 6 | # Required-Stop: $remote_fs $syslog 7 | # Should-Start: 8 | # Should-Stop: 9 | # Default-Start: 2 3 4 5 10 | # Default-Stop: 0 1 6 11 | # Short-Description: blinkd sysv init script 12 | # Description: Blinking Led server 13 | ### END INIT INFO 14 | # 15 | SERVER_NAME=blinkd 16 | DESC="Blinking Led server" 17 | PGM_NAME=Blinkd 18 | PGM_OPT="-D -p 0" 19 | 20 | PIDFILE=/var/run/$PGM_NAME.pid 21 | PGM=/usr/local/bin/$PGM_NAME 22 | 23 | test -x $PGM || exit 0 24 | 25 | . /lib/lsb/init-functions 26 | 27 | niceness=0 28 | pgm_args="--quiet --oknodo --nicelevel $niceness --pidfile $PIDFILE --exec $PGM" 29 | 30 | daemon_start () { 31 | log_daemon_msg "Starting $DESC" "$SERVER_NAME" 32 | 33 | rm -f $PIDFILE 34 | start-stop-daemon --start $pgm_args -- $PGM_OPT 35 | log_end_msg $? 36 | return $? 37 | } 38 | 39 | daemon_stop () { 40 | log_daemon_msg "Stopping $DESC" "$SERVER_NAME" 41 | 42 | start-stop-daemon --stop $pgm_args --retry TERM/5/KILL/10 43 | log_end_msg $? 44 | return $? 45 | } 46 | 47 | 48 | case "$1" in 49 | start) 50 | daemon_start || exit 1 51 | ;; 52 | stop) 53 | daemon_stop || exit 1 54 | ;; 55 | force-reload|restart) 56 | daemon_stop 57 | sleep 1 58 | daemon_start || exit 1 59 | ;; 60 | status) 61 | status_of_proc $PGM "$DESC" 62 | ;; 63 | *) 64 | echo "Usage: /etc/init.d/$SERVER_NAME {start|stop|restart|force-reload|status}" 65 | exit 1 66 | esac 67 | 68 | exit 0 69 | -------------------------------------------------------------------------------- /examples/Blink-Daemon/main.cpp: -------------------------------------------------------------------------------- 1 | // Blinkd 2 | 3 | // This example shows how to make a daemon that lets you blinking a led on Pi board 4 | 5 | // Created 10 February 2019 6 | 7 | // This example code is in the public domain. 8 | #include // All the magic is here ;-) 9 | using namespace Piduino; 10 | 11 | int ledPin = 0; 12 | unsigned long highDelay = 500; 13 | unsigned long lowDelay = 500; 14 | 15 | void setup() { 16 | 17 | auto pin_option = CmdLine.add> ("p", "pin", "set pin number"); 18 | CmdLine.add> ("H", "high", "set high state delay", 500, &highDelay); 19 | CmdLine.add> ("L", "low", "set low state delay", 500, &lowDelay); 20 | CmdLine.parse (argc, argv); 21 | 22 | if (! pin_option->is_set()) { 23 | Console.println ("Usage: Blinkd -p pin_number [-H high_delay] [-L low_delay]"); 24 | exit (EXIT_FAILURE); 25 | } 26 | ledPin = pin_option->value(); 27 | 28 | // initialize digital pin ledPin as an output. 29 | pinMode (ledPin, OUTPUT); 30 | } 31 | 32 | void loop () { 33 | // Press Ctrl+C to abort ... 34 | digitalWrite (ledPin, HIGH); 35 | delay (highDelay); 36 | digitalWrite (ledPin, LOW); 37 | delay (lowDelay); 38 | } 39 | -------------------------------------------------------------------------------- /examples/Blink/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Blink/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Blink/Blink.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Blink) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Blink/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Blink/main.cpp: -------------------------------------------------------------------------------- 1 | // Blink 2 | 3 | // Turns an LED on for one second, then off for one second, repeatedly. 4 | 5 | // Created 8 March 2018 6 | 7 | // This example code is in the public domain. 8 | #include // All the magic is here ;-) 9 | 10 | // Be careful !!! Before launching this program : 11 | // -> Check that the pin below is well connected to an LED ! <- 12 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 13 | 14 | void setup() { 15 | // initialize digital pin ledPin as an output. 16 | pinMode (ledPin, OUTPUT); 17 | } 18 | 19 | void loop () { 20 | // Press Ctrl+C to abort ... 21 | digitalWrite (ledPin, HIGH); // turn the LED on (HIGH is the voltage level) 22 | delay (1000); // wait for a second 23 | digitalWrite (ledPin, LOW); // turn the LED off by making the voltage LOW 24 | delay (1000); // wait for a second 25 | } 26 | // ----------------------------------------------------------------------------- 27 | -------------------------------------------------------------------------------- /examples/Button/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Button/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Button/Button.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Button/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Button) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Button/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Button/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Button 3 | 4 | Turns on and off a light emitting diode(LED) connected to digital pin 0, 5 | when pressing a pushbutton attached to pin 3. 6 | 7 | The circuit: 8 | - LED attached from pin 0 to ground 9 | - pushbutton attached to pin 3 from GND 10 | 11 | This example code is in the public domain. 12 | 13 | http://www.arduino.cc/en/Tutorial/Button 14 | */ 15 | #include // All the magic is here ;-) 16 | 17 | // constants won't change. They're used here to set pin numbers: 18 | // Be careful !!! Before launching this program : 19 | // -> Check that the pin below is well connected to an LED ! <- 20 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 21 | const int buttonPin = 3; // Header Pin 15: GPIO22 for RPi, GPIOA3 for NanoPi 22 | 23 | // variables will change: 24 | int buttonState = HIGH; // variable for reading the pushbutton status 25 | 26 | void setup() { 27 | // initialize the LED pin as an output: 28 | pinMode (ledPin, OUTPUT); 29 | // initialize the pushbutton pin as an input with pull-up resistor: 30 | pinMode (buttonPin, INPUT_PULLUP); 31 | } 32 | 33 | void loop () { 34 | // Press Ctrl+C to abort ... 35 | 36 | // read the state of the pushbutton value: 37 | buttonState = digitalRead (buttonPin); 38 | 39 | // check if the pushbutton is pressed. If it is, the buttonState is LOW: 40 | if (buttonState == LOW) { 41 | // turn LED on: 42 | digitalWrite (ledPin, HIGH); 43 | } 44 | else { 45 | // turn LED off: 46 | digitalWrite (ledPin, LOW); 47 | } 48 | } 49 | // ----------------------------------------------------------------------------- 50 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(Blink) 4 | add_subdirectory(Blink-Daemon) 5 | add_subdirectory(Button) 6 | add_subdirectory(Communication) 7 | add_subdirectory(Fade) 8 | add_subdirectory(Interrupt) 9 | add_subdirectory(NoArduino) 10 | add_subdirectory(Spi) 11 | add_subdirectory(Wire) 12 | -------------------------------------------------------------------------------- /examples/Communication/ASCIITable/ASCIITable.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/ASCIITable/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(ASCIITable) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(ASCIITable) 4 | add_subdirectory(Console) 5 | add_subdirectory(ReadASCIIString) 6 | add_subdirectory(SerialPrint) 7 | add_subdirectory(SerialPong) 8 | add_subdirectory(SerialPing) 9 | -------------------------------------------------------------------------------- /examples/Communication/Console/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Console) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/Console/Console.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/ReadASCIIString/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(ReadASCIIString) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/ReadASCIIString/ReadASCIIString.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/ReadASCIIString/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Reading a serial ASCII-encoded string. 3 | 4 | This sketch demonstrates the Serial parseInt() function. 5 | It looks for an ASCII string of comma-separated values. 6 | It parses them into ints, and uses those to fade an RGB LED. 7 | 8 | Circuit: Common-Cathode RGB LED wired like so: 9 | - red anode: digital pin 3 10 | - green anode: digital pin 5 11 | - blue anode: digital pin 6 12 | - cathode: GND 13 | 14 | created 13 Apr 2012 15 | by Tom Igoe 16 | modified 14 Mar 2016 17 | by Arturo Guadalupi 18 | 19 | This example code is in the public domain. 20 | */ 21 | #include // All the magic is here ;-) 22 | 23 | // Be careful !!! Before launching this program : 24 | // -> Check that the pins below is well connected to an LED ! <- 25 | const int redPin = 2; 26 | const int greenPin = 3; 27 | const int bluePin = 7; 28 | 29 | void setup() { 30 | // initialize serial: 31 | Serial.begin(115200); 32 | // make the pins outputs: 33 | pinMode(redPin, OUTPUT); 34 | pinMode(greenPin, OUTPUT); 35 | pinMode(bluePin, OUTPUT); 36 | } 37 | 38 | void loop() { 39 | // if there's any serial available, read it: 40 | while (Serial.available() > 0) { 41 | 42 | // look for the next valid integer in the incoming serial stream: 43 | int red = Serial.parseInt(); 44 | // do it again: 45 | int green = Serial.parseInt(); 46 | // do it again: 47 | int blue = Serial.parseInt(); 48 | 49 | // look for the newline. That's the end of your sentence: 50 | if (Serial.read() == '\n') { 51 | // constrain the values to 0 - 255 and invert 52 | // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" 53 | red = 255 - constrain(red, 0, 255); 54 | green = 255 - constrain(green, 0, 255); 55 | blue = 255 - constrain(blue, 0, 255); 56 | 57 | // fade the red, green, and blue legs of the LED: 58 | analogWrite(redPin, red); 59 | analogWrite(greenPin, green); 60 | analogWrite(bluePin, blue); 61 | 62 | // print the three numbers in one string as hexadecimal: 63 | Serial.print(red, HEX); 64 | Serial.print(green, HEX); 65 | Serial.println(blue, HEX); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/Communication/SerialPing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(SerialPing) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/SerialPing/SerialPing.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/SerialPong/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(SerialPong) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/SerialPong/SerialPong.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/SerialPong/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | // SerialPong 3 | 4 | // This program demonstrates a basic "Serial Pong" application where it reads 5 | // a message ("ping") from the serial port, converts it to lowercase, and sends 6 | // it back as a response ("pong"). It also outputs the received and sent messages 7 | // to the console for debugging purposes. 8 | // The program initializes the console for debugging and sets up serial communication 9 | // with a specified baud rate and configuration. It continuously listens for incoming 10 | // serial data, processes it, and responds accordingly. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | // Include the Piduino library for serial communication and utilities 16 | #include 17 | 18 | // Console baud rate for debugging output 19 | const unsigned long ConsoleBaudrate = 115200; 20 | 21 | // Serial communication constants 22 | const unsigned long SerialBaudrate = 38400; // Baud rate for serial communication 23 | const uint8_t SerialConfig = SERIAL_8E1; // Serial configuration: 8 data bits, even parity, 1 stop bit 24 | 25 | void setup() { 26 | 27 | // Initialize the console for debugging 28 | Console.begin(ConsoleBaudrate); 29 | Console.print("SerialPong to "); 30 | Console.println(Serial.portName()); // Print the name of the serial port 31 | 32 | // Initialize the serial communication with the specified baud rate and configuration 33 | Serial.begin(SerialBaudrate, SerialConfig); 34 | while (!Serial) { 35 | ; // Wait for the serial port to connect (needed for native USB ports) 36 | } 37 | } 38 | 39 | void loop() { 40 | String ping; // Variable to store the received message 41 | 42 | // Check if there is any data available on the serial port 43 | while (Serial.available() > 0) { 44 | int c = Serial.read(); // Read one character from the serial port 45 | delay(10); // Small delay to ensure proper reading 46 | if (c > 0) { // If the character was successfully read 47 | ping.concat((char)c); // Append the character to the "ping" string 48 | } 49 | } 50 | 51 | // If a message ("ping") was received 52 | if (ping.length() > 0) { 53 | String pong; // Variable to store the response message 54 | 55 | // Print the received message to the console 56 | Console.print(ping); 57 | Console.println(); 58 | 59 | // Copy the received message and convert it to lowercase 60 | pong = ping; 61 | pong.toLowerCase(); 62 | 63 | // Send the modified message ("pong") back over serial 64 | Serial.print(pong); 65 | Serial.flush(); 66 | 67 | // Print the modified message to the console 68 | Console.print(pong); 69 | Console.println(); 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /examples/Communication/SerialPrint/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(SerialPrint) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Communication/SerialPrint/SerialPrint.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Communication/SerialPrint/main.cpp: -------------------------------------------------------------------------------- 1 | // SerialPrint 2 | 3 | // This code demonstrates a simple serial communication example using the Piduino library. 4 | // It sends a predefined message ("Hello World, Have a nice day!") over the serial port and 5 | // simultaneously prints the same message to the console for debugging. The process repeats 6 | // every 500 milliseconds, ensuring the message is fully transmitted before each iteration. 7 | 8 | // This example code is in the public domain. 9 | 10 | #include // Include the Piduino library for serial communication and utilities 11 | 12 | // Console baud rate for debugging output 13 | const unsigned long ConsoleBaudrate = 115200; 14 | 15 | // Serial communication constants 16 | const unsigned long SerialBaudrate = 38400; // Baud rate for serial communication 17 | const uint8_t SerialConfig = SERIAL_8E1; // Serial configuration: 8 data bits, even parity, 1 stop bit 18 | 19 | // Message to send over serial 20 | const String hello = "Hello World, Have a nice day!"; 21 | 22 | void setup() { 23 | 24 | // Initialize the console for debugging 25 | Console.begin(ConsoleBaudrate); 26 | Console.print("SerialPrint to "); 27 | Console.println(Serial.portName()); // Print the name of the serial port 28 | 29 | // Initialize the serial communication with the specified baud rate and configuration 30 | Serial.begin(SerialBaudrate, SerialConfig); 31 | while (!Serial) { 32 | ; // Wait for the serial port to connect (needed for native USB ports) 33 | } 34 | } 35 | 36 | void loop() { 37 | 38 | // Send the "hello" message over serial 39 | Serial.print(hello); 40 | Serial.flush(); // Ensure the message is fully transmitted 41 | 42 | // Print the same message to the console for debugging 43 | Console.print(hello); 44 | Console.println(); 45 | 46 | // Wait for 500 milliseconds before repeating 47 | delay(500); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /examples/Fade/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Fade/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Fade/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Fade) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Fade/Fade.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Fade/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Fade/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Fade 3 | 4 | This example shows how to fade an LED on pin 0 using the analogWrite() 5 | function. 6 | 7 | This example code is in the public domain. 8 | 9 | http://www.arduino.cc/en/Tutorial/Fade 10 | */ 11 | #include // All the magic is here ;-) 12 | 13 | 14 | // Be careful !!! Before launching this program : 15 | // -> Check that the pin below is well connected to an LED ! <- 16 | const int led = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 17 | 18 | int brightness = 0; // how bright the LED is 19 | int fadeAmount = 5; // how many points to fade the LED by 20 | 21 | // the setup routine runs once when you press reset: 22 | void setup() { 23 | // declare pin 0 to be an output: 24 | pinMode(led, OUTPUT); 25 | } 26 | 27 | // the loop routine runs over and over again forever: 28 | // Press Ctrl+C to abort ... 29 | void loop() { 30 | // set the brightness of pin 0: 31 | analogWrite(led, brightness); 32 | 33 | // change the brightness for next time through the loop: 34 | brightness = brightness + fadeAmount; 35 | 36 | // reverse the direction of the fading at the ends of the fade: 37 | if (brightness <= 0 || brightness >= 255) { 38 | fadeAmount = -fadeAmount; 39 | } 40 | // wait for 30 milliseconds to see the dimming effect 41 | delay(30); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Interrupt/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Interrupt/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Interrupt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(Interrupt) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Interrupt/Interrupt.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Interrupt/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Interrupt/main.cpp: -------------------------------------------------------------------------------- 1 | // interrupt 2 | 3 | // This program captures the rising and falling edges sent on a digital pin. 4 | // A led copies the state of the input signal and the console displays the 5 | // time differences between edges. 6 | 7 | // How to make this program work ? 8 | 9 | // 1- Connect the irqPin to another pin of the GPIO connector with a wire 10 | // (eg Pin 10: Pin Header 24, GPIOC3 for NanoPi, GPIO8 for RaspberryPi). 11 | 12 | // 2- Configure pin 10 as output with the pido utility: 13 | // $ pido mode 10 out 14 | 15 | // 3- Run this program: 16 | // $ sudo ./interrupt 17 | // You must be root to run this program (use sudo) ! 18 | 19 | // 4- Generate a clock signal on pin 10 with the pido utility: 20 | // $ pido blink 10 100 21 | 22 | // 5- The console should display the time differences between edges (100ms): 23 | // Press Ctrl+C to abort ... 24 | // 27047: 0 25 | // 100: 1 26 | // 100: 0 27 | // 100: 1 28 | 29 | // Created 6 March 2018 30 | // This example code is in the public domain. 31 | #include // All the magic is here ;-) 32 | 33 | // Be careful !!! Before launching this program : 34 | // -> Check that the pin below is well connected to an LED ! <- 35 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 36 | const int irqPin = 3; // Header Pin 15: GPIO22 for RPi, GPIOA3 for NanoPi 37 | 38 | unsigned long t1, t2; // for calculating time differences between interruptions 39 | 40 | // ----------------------------------------------------------------------------- 41 | // Interrupt Service Routine 42 | // Called at each interruption triggered by a rising or falling edge 43 | void isr() { 44 | int value; 45 | 46 | t2 = millis(); // second time 47 | 48 | // reads the binary value 49 | value = digitalRead (irqPin); 50 | 51 | // copy irq value to led 52 | digitalWrite (ledPin, value); 53 | 54 | // prints the time difference between edges and the state of the irq pin. 55 | Console.print (t2 - t1); 56 | Console.print (":\t"); 57 | Console.println (value); 58 | t1 = t2; // the new time becomes the first for the next irq 59 | } 60 | 61 | void setup() { 62 | 63 | Console.begin (115200); 64 | // initialize digital pin ledPin as an output. 65 | pinMode (ledPin, OUTPUT); 66 | // initialize digital pin irqPin as an input with pull-up (for button ?) 67 | pinMode (irqPin, INPUT_PULLUP); 68 | // attach interrupt service routine isr to irqPin, called for each edge 69 | attachInterrupt (irqPin, isr, CHANGE); 70 | } 71 | 72 | void loop () { 73 | 74 | // Press Ctrl+C to abort ... 75 | delay (-1); // nothing to do, we sleep ... 76 | } 77 | // ----------------------------------------------------------------------------- 78 | -------------------------------------------------------------------------------- /examples/NoArduino/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(Gpio) 4 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/Blink.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(GpioBlink) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Blink/main.cpp: -------------------------------------------------------------------------------- 1 | // Blink example 2 | // by epsilonrt 3 | 4 | // This program flashes an LED connected to a GPIO pin with a frequency of 2 Hz. 5 | 6 | // Created 6 March 2018 7 | 8 | // This example code is in the public domain. 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | using namespace Piduino; 15 | 16 | // Be careful !!! Before launching this program : 17 | // -> Check that the pin below is well connected to an LED ! <- 18 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 19 | 20 | Pin & led = gpio.pin (ledPin); // led is a reference on pin 11 of the GPIO 21 | 22 | // ----------------------------------------------------------------------------- 23 | int main (int argc, char **argv) { 24 | 25 | 26 | gpio.open(); 27 | led.setMode (Pin::ModeOutput); // the led pin is an output 28 | led.write (0); // turn off the led 29 | 30 | cout << "Press Ctrl+C to abort ..." << endl; 31 | for (;;) { 32 | 33 | led.toggle(); // blinking led 34 | clk.delay (1000); 35 | cout << '.' << flush; // print one point per second 36 | } 37 | 38 | return 0; 39 | } 40 | /* ========================================================================== */ 41 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(Blink) 4 | add_subdirectory(Fade) 5 | add_subdirectory(Interrupt) 6 | add_subdirectory(WaitForInt) 7 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(GpioFade) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/Fade.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Fade/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Fade 3 | 4 | This example shows how to fade an LED on pin 0 using the analogWrite() 5 | function. 6 | 7 | This example code is in the public domain. 8 | 9 | http://www.arduino.cc/en/Tutorial/Fade 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | using namespace Piduino; 18 | 19 | // Be careful !!! Before launching this program : 20 | // -> Check that the pin below is well connected to an LED ! <- 21 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 22 | 23 | Pin & led = gpio.pin (ledPin); // led is a reference on pin 11 of the GPIO 24 | 25 | // ----------------------------------------------------------------------------- 26 | int main (int argc, char **argv) { 27 | long inc, min, max; 28 | gpio.open(); 29 | cout << "Press Ctrl+C to abort ..." << endl; 30 | 31 | if (led.dac() == nullptr) { 32 | 33 | if (! led.setDac (new GpioPwm (&led))) { 34 | exit(EXIT_FAILURE); 35 | } 36 | } 37 | 38 | min = led.dac()->min(); 39 | max = led.dac()->max() + 1; 40 | inc = (max - min) / 128; 41 | 42 | for (;;) { 43 | 44 | // fade in from min to max in increments of 5 points: 45 | for (long fadeValue = min; fadeValue <= max; fadeValue += inc) { 46 | // sets the value (range from 0 to 255): 47 | led.analogWrite (fadeValue); 48 | // wait for 30 milliseconds to see the dimming effect 49 | clk.delay (100); 50 | cout << '+' << flush; // print one point per second 51 | } 52 | cout << endl; 53 | clk.delay (1000); 54 | 55 | // fade out from max to min in increments of 5 points: 56 | for (long fadeValue = max; fadeValue >= min; fadeValue -= inc) { 57 | // sets the value (range from 0 to 255): 58 | led.analogWrite (fadeValue); 59 | // wait for 30 milliseconds to see the dimming effect 60 | clk.delay (100); 61 | cout << '-' << flush; // print one point per second 62 | } 63 | cout << endl; 64 | clk.delay (1000); 65 | } 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Interrupt/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Interrupt/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Interrupt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(GpioInterrupt) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Interrupt/Interrupt.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/Interrupt/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(GpioWaitForInt) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/WaitForInt.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/NoArduino/Gpio/WaitForInt/main.cpp: -------------------------------------------------------------------------------- 1 | // waitForInt() example 2 | 3 | // This program toggles the state of a led at each rising or falling edge sent 4 | // to an input used as an interrupt request. 5 | // The time difference between 2 successive edges is displayed. 6 | 7 | // Created 6 March 2018 8 | 9 | // This example code is in the public domain. 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | using namespace Piduino; 16 | 17 | // Be careful !!! Before launching this program : 18 | // -> Check that the pin below is well connected to an LED ! <- 19 | const int ledPin = 0; // Header Pin 11: GPIO17 for RPi, GPIOA0 for NanoPi 20 | const int irqPin = 3; // Header Pin 15: GPIO22 for RPi, GPIOA3 for NanoPi 21 | 22 | Pin & led = gpio.pin (ledPin); // led is a reference on pin 11 of the GPIO 23 | Pin & irq = gpio.pin (irqPin); // irq is a reference on pin 15 of the GPIO 24 | unsigned long t1, t2; // for calculating time differences between interruptions 25 | 26 | // ----------------------------------------------------------------------------- 27 | int main (int argc, char **argv) { 28 | 29 | gpio.open(); 30 | led.setMode(Pin::ModeOutput); // the led pin is an output 31 | led.write(0); // turn off the led 32 | irq.setPull(Pin::PullUp); // activates the pull-up resistor if the input is 33 | // not connected or connected to a push button. 34 | irq.setMode(Pin::ModeInput); // the irq pin is an input that will be used 35 | // as an interrupt request. 36 | 37 | cout << "Press Ctrl+C to abort ..." << endl; 38 | 39 | t1 = clk.millis(); // first time 40 | for (;;) { // Infinite loop, Press Ctrl+C to abort ... 41 | 42 | irq.waitForInterrupt(Pin::EdgeBoth); // waiting for a rising or falling edge 43 | // under interruption 44 | t2 = clk.millis(); // second time 45 | led.toggle(); // toggle the led state 46 | cout << t2 - t1 << ":\t" << irq.read() << endl; // prints the time 47 | // difference between edges and the state of the irq pin. 48 | t1 = t2; // the new time becomes the first for the next loop 49 | } 50 | 51 | return 0; 52 | } 53 | /* ========================================================================== */ 54 | -------------------------------------------------------------------------------- /examples/NoArduino/piduino-examples.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/Spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(SpiMemoryMb85rs) 4 | add_subdirectory(SpiPressureSensorHsc) 5 | -------------------------------------------------------------------------------- /examples/Spi/SpiMemoryMb85rs/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Spi/SpiMemoryMb85rs/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Spi/SpiMemoryMb85rs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(SpiMemoryMb85rs) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | add_executable(${PROJECT_NAME} main.cpp mb85rs.cpp) 14 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 15 | 16 | set(PROGRAM_PERMISSIONS_BY_ROOT 17 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 18 | GROUP_READ GROUP_EXECUTE 19 | WORLD_READ WORLD_EXECUTE SETUID) 20 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 21 | -------------------------------------------------------------------------------- /examples/Spi/SpiMemoryMb85rs/SpiMemoryMb85rs.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Spi/SpiMemoryMb85rs/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Spi/SpiPressureSensorHsc/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Spi/SpiPressureSensorHsc/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Spi/SpiPressureSensorHsc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(SpiPressureSensorHsc) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Spi/SpiPressureSensorHsc/SpiPressureSensorHsc.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Spi/SpiPressureSensorHsc/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Template/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Template/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(#{PROJECT}) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Template/README.md: -------------------------------------------------------------------------------- 1 | # Piduino CMake Template 2 | 3 | This is a template for creating a Piduino project using CMake. It provides a basic structure and configuration to get started with your project. 4 | 5 | 6 | It is designed to be used with the [Project Templates](https://marketplace.visualstudio.com/items?itemName=cantonios.project-templates) extension for Visual Studio Code. 7 | 8 | ## Getting Started 9 | 10 | 1. Clone this repository to your local machine. 11 | 2. Open the project in Visual Studio Code. 12 | 3. Install the [Project Templates](https://marketplace.visualstudio.com/items?itemName=cantonios.project-templates) extension if you haven't already. 13 | 4. Use the extension to create a new template project based on this template. 14 | -------------------------------------------------------------------------------- /examples/Template/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Template/main.cpp: -------------------------------------------------------------------------------- 1 | // #{PROJECT} 2 | // by #{AUTHOR} 3 | // #{DESCRIPTION} 4 | #include // All the magic is here ;-) 5 | 6 | 7 | 8 | void setup() { 9 | // Place your setup code here, to run once: 10 | // e.g. pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output 11 | 12 | } 13 | 14 | void loop () { 15 | // Press Ctrl+C to abort ... 16 | 17 | // Place your main code here, to run repeatedly: 18 | // e.g. digitalWrite(LED_BUILTIN, HIGH); // Turn the LED on (HIGH is the voltage level) 19 | // e.g. delay(1000); // Wait for a second 20 | // e.g. digitalWrite(LED_BUILTIN, LOW); // Turn the LED off by making the voltage LOW 21 | // e.g. delay(1000); // Wait for a second 22 | } 23 | -------------------------------------------------------------------------------- /examples/Wire/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | add_subdirectory(WireDigitalPotentiometer) 4 | add_subdirectory(WireMasterReader) 5 | add_subdirectory(WireMasterWriter) 6 | add_subdirectory(WireRtcBq32k) 7 | -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(WireDigitalPotentiometer) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/WireDigitalPotentiometer.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Wire/WireDigitalPotentiometer/main.cpp: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | #include // All the magic is here ;-) 14 | 15 | #include 16 | 17 | void setup() { 18 | Wire.begin(); // join i2c bus (address optional for master) 19 | } 20 | 21 | byte val = 0; 22 | 23 | void loop() { 24 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 25 | // device address is specified in datasheet 26 | Wire.write(byte(0x00)); // sends instruction byte 27 | Wire.write(val); // sends potentiometer value byte 28 | Wire.endTransmission(); // stop transmitting 29 | 30 | val++; // increment value 31 | if (val == 64) { // if reached 64th position (max) 32 | val = 0; // start over from lowest value 33 | } 34 | delay(500); 35 | } 36 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(WireMasterReader) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/WireMasterReader.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Wire/WireMasterReader/main.cpp: -------------------------------------------------------------------------------- 1 | // Wire Master Reader 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Reads data from an I2C/TWI slave device 6 | // Refer to the "Wire Slave Sender" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | #ifdef __unix__ 12 | #include // All the magic is here ;-) 13 | #else 14 | // Defines the serial port as the console on the Arduino platform 15 | #define Console Serial 16 | #endif 17 | 18 | #include 19 | 20 | void setup() { 21 | 22 | Console.begin (115200); 23 | Wire.begin(); // join i2c bus (address optional for master) 24 | } 25 | 26 | void loop() { 27 | Wire.requestFrom (8, 6); // request 6 bytes from slave device #8 28 | 29 | while (Wire.available()) { // slave may send less than requested 30 | char c = Wire.read(); // receive a byte as character 31 | Console.print (c); // print the character 32 | } 33 | 34 | delay (500); 35 | } 36 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(WireMasterWriter) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/WireMasterWriter.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Wire/WireMasterWriter/main.cpp: -------------------------------------------------------------------------------- 1 | // Wire Master Writer 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Writes data to an I2C/TWI slave device 6 | // Refer to the "Wire Slave Receiver" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | #include // All the magic is here ;-) 12 | #include 13 | 14 | void setup() { 15 | Wire.begin(); // join i2c bus (address optional for master) 16 | } 17 | 18 | byte x = 0; 19 | 20 | void loop() { 21 | Wire.beginTransmission(8); // transmit to device #8 22 | Wire.write("x is "); // sends five bytes 23 | Wire.write(x); // sends one byte 24 | Wire.endTransmission(); // stop transmitting 25 | 26 | x++; 27 | delay(500); 28 | } 29 | -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/.gitignore: -------------------------------------------------------------------------------- 1 | *.map 2 | *.lss 3 | *.sym 4 | *.bak 5 | .codelite 6 | .clang 7 | compile_commands.json 8 | *.a 9 | *.so 10 | obj/ 11 | version.* 12 | *build*/ 13 | work/ 14 | -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(gdbasroot) Launch with sudo", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | // Resolved by CMake Tools: 9 | "program": "${command:cmake.launchTargetPath}", 10 | "args": [ 11 | ], 12 | "stopAtEntry": true, 13 | "cwd": "${workspaceFolder}", 14 | "environment": [ 15 | { 16 | // add the directory where our target was built to the PATHs 17 | // it gets resolved by CMake Tools: 18 | "name": "PATH", 19 | "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}" 20 | } 21 | ], 22 | "externalConsole": false, 23 | "miDebuggerPath": "${workspaceFolder}/bin/gdbasroot", 24 | "MIMode": "gdb", 25 | "setupCommands": [ 26 | { 27 | "description": "Enable pretty-printing for gdb", 28 | "text": "-enable-pretty-printing", 29 | "ignoreFailures": true 30 | } 31 | ] 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # 4 | project(WireRtcBq32k) 5 | 6 | set(CMAKE_CXX_STANDARD 11) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | # set(CMAKE_VERBOSE_MAKEFILE ON) 9 | 10 | find_package(PkgConfig REQUIRED) 11 | pkg_check_modules(PIDUINO REQUIRED IMPORTED_TARGET piduino) 12 | 13 | file(GLOB SOURCES *.cpp) 14 | add_executable(${PROJECT_NAME} ${SOURCES}) 15 | target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::PIDUINO) 16 | 17 | set(PROGRAM_PERMISSIONS_BY_ROOT 18 | OWNER_WRITE OWNER_READ OWNER_EXECUTE 19 | GROUP_READ GROUP_EXECUTE 20 | WORLD_READ WORLD_EXECUTE SETUID) 21 | install(TARGETS ${PROJECT_NAME} DESTINATION bin PERMISSIONS ${PROGRAM_PERMISSIONS_BY_ROOT}) 22 | -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/WireRtcBq32k.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/bin/gdbasroot: -------------------------------------------------------------------------------- 1 | sudo /usr/bin/gdb "$@" -------------------------------------------------------------------------------- /examples/Wire/WireRtcBq32k/main.cpp: -------------------------------------------------------------------------------- 1 | // I2C RTC BQ32000 2 | 3 | // Demonstrates use of the Wire library 4 | // Controls BQ32000 Real Time Clock via I2C/TWI 5 | 6 | // Console is used with PIDUINO as Serial with ARDUINO. 7 | 8 | // Created 16 August 2018 9 | // by Pascal JEAN https://github.com/epsilonrt 10 | 11 | // This example code is in the public domain. 12 | #ifdef __unix__ 13 | #include // All the magic is here ;-) 14 | #else 15 | // Defines the serial port as the console on the Arduino platform 16 | #define Console Serial 17 | #endif 18 | 19 | #include 20 | 21 | void printBcdDigit (byte val, bool end = false) { 22 | val = (val / 16 * 10) + (val % 16); // BCD to DEC 23 | 24 | if (val < 10) { 25 | Console.write ('0'); // leading zero 26 | } 27 | if (end) { 28 | 29 | Console.println (val); 30 | } 31 | else { 32 | 33 | Console.print (val); 34 | Console.write (':'); 35 | } 36 | } 37 | 38 | void setup() { 39 | 40 | Console.begin (115200); 41 | Wire.begin(); // Starting the i2c master 42 | } 43 | 44 | void loop() { 45 | 46 | Wire.beginTransmission (0x68); // start of the frame for the RTC at slave address 0x68 47 | Wire.write (0); // write the address of the register in the RTC, 0 first register 48 | Wire.endTransmission (false); // restart condition 49 | Wire.requestFrom (0x68, 3); // 3-byte read request 50 | 51 | if (Wire.available() == 3) { // if the 3 bytes have been read 52 | byte sec = Wire.read(); 53 | byte min = Wire.read(); 54 | byte hour = Wire.read() & 0x3F; // remove CENT_EN and CENT LSB bits 55 | 56 | // time display 57 | printBcdDigit (hour); 58 | printBcdDigit (min); 59 | printBcdDigit (sec, true); 60 | } 61 | exit (0); // exit the loop() function without ever coming back. 62 | // On Arduino, exit() performs an infinite loop as explained on 63 | // https://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html 64 | // on a Pi board, exit () stops the program by returning the supplied value. 65 | } 66 | -------------------------------------------------------------------------------- /examples/vscode-sudo.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/examples/vscode-sudo.tar.gz -------------------------------------------------------------------------------- /include/piduino/arduino/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect (IPAddress ip, uint16_t port) = 0; 30 | virtual int connect (const char *host, uint16_t port) = 0; 31 | virtual size_t write (uint8_t) = 0; 32 | virtual size_t write (const uint8_t *buf, size_t size) = 0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read (uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress (IPAddress& addr) { 43 | return addr.raw_address(); 44 | }; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/piduino/arduino/Console.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef Piconsole_h 19 | #define Piconsole_h 20 | 21 | #include "Terminal.h" 22 | #include 23 | 24 | class PiConsole : public Terminal { 25 | 26 | public: 27 | PiConsole(); 28 | virtual void begin (unsigned long speed_dummy = 0, uint8_t config_dummy = 0); 29 | virtual void end(); 30 | 31 | protected: 32 | virtual std::ostream & os(); 33 | virtual Piduino::TerminalNotifier & notifier(); 34 | 35 | private: 36 | Piduino::FileDevice _keyb; 37 | Piduino::TerminalNotifier _notifier; 38 | }; 39 | #endif 40 | -------------------------------------------------------------------------------- /include/piduino/arduino/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | class Print; 24 | 25 | /** The Printable class provides a way for new classes to allow themselves to be printed. 26 | By deriving from Printable and implementing the printTo method, it will then be possible 27 | for users to print out instances of this class by passing them into the usual 28 | Print::print and Print::println methods. 29 | */ 30 | 31 | class Printable 32 | { 33 | public: 34 | virtual size_t printTo(Print& p) const = 0; 35 | }; 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /include/piduino/arduino/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() = 0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/piduino/arduino/Terminal.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef Terminal_h 18 | #define Terminal_h 19 | 20 | #include 21 | #include 22 | #include "Stream.h" 23 | //#include "Arduino.h" 24 | 25 | class Terminal : public Stream { 26 | 27 | public: 28 | Terminal(); 29 | virtual ~Terminal() {} 30 | 31 | int getReadError() { 32 | return read_error; 33 | } 34 | void clearReadError() { 35 | setReadError (0); 36 | } 37 | 38 | virtual void begin (unsigned long speed_dummy = 0, uint8_t config_dummy = 0); 39 | virtual void end(); 40 | 41 | virtual int available(); 42 | virtual int read(); 43 | virtual int peek(); 44 | 45 | virtual size_t write (uint8_t); 46 | virtual size_t write (const uint8_t *buffer, size_t size); 47 | virtual size_t write (const String & str); 48 | virtual void flush(); 49 | 50 | size_t write (const char *str) { 51 | 52 | return write (String (str)); 53 | } 54 | 55 | inline size_t write (unsigned long n) { 56 | 57 | return write ( (uint8_t) n); 58 | } 59 | 60 | inline size_t write (long n) { 61 | 62 | return write ( (uint8_t) n); 63 | } 64 | 65 | inline size_t write (unsigned int n) { 66 | 67 | return write ( (uint8_t) n); 68 | } 69 | 70 | inline size_t write (int n) { 71 | 72 | return write ( (uint8_t) n); 73 | } 74 | 75 | protected: 76 | virtual std::ostream & os() = 0; 77 | virtual Piduino::TerminalNotifier & notifier() = 0; 78 | virtual int timedRead(); // read stream with timeout 79 | virtual int timedPeek(); // peek stream with timeout 80 | virtual size_t writeln(); 81 | 82 | void setReadError (int err = 1) { 83 | read_error = err; 84 | } 85 | 86 | private: 87 | int read_error; 88 | std::ostream::iostate os_state; 89 | }; 90 | #endif 91 | -------------------------------------------------------------------------------- /include/piduino/arduino/WString.h: -------------------------------------------------------------------------------- 1 | /* 2 | WString.h - String library for Wiring & Arduino 3 | ...mostly rewritten by Paul Stoffregen... 4 | Copyright (c) 2009-10 Hernando Barragan. All right reserved. 5 | Copyright 2011, Paul Stoffregen, paul@pjrc.com 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __WSTRING_H__ 23 | #define __WSTRING_H__ 24 | 25 | #include "pgmspace.h" 26 | 27 | #ifdef __cplusplus 28 | #include 29 | 30 | class __FlashStringHelper; 31 | #define F(string_literal) (reinterpret_cast(PSTR(string_literal))) 32 | 33 | typedef Piduino::String String; 34 | 35 | #endif /* __cplusplus defined */ 36 | /* ========================================================================== */ 37 | #endif /*__WSTRING_H__ defined */ 38 | -------------------------------------------------------------------------------- /include/piduino/arduino/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.h - TWI/I2C library for Arduino & Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | Modified 2018 by Pascal JEAN for Piduino Library 21 | */ 22 | 23 | #ifndef TwoWire_h 24 | #define TwoWire_h 25 | 26 | #include 27 | #include 28 | 29 | #define BUFFER_LENGTH 32 30 | 31 | // WIRE_HAS_END means Wire has end() 32 | #define WIRE_HAS_END 1 33 | 34 | class TwoWire : public Piduino::I2cDev { 35 | 36 | public: 37 | TwoWire(int id = Info::defaultBus().id()) : Piduino::I2cDev(id) {} 38 | virtual ~TwoWire() {} 39 | void begin() { 40 | if (!open ()) { 41 | throw std::system_error (errno, std::system_category(), 42 | "Error when opening the I2C bus " + 43 | bus().path()); 44 | } 45 | } 46 | void begin (int id) { 47 | setBus (id); 48 | if (!open ()) { 49 | throw std::system_error (errno, std::system_category(), 50 | "Error when opening the I2C bus " + 51 | bus().path()); 52 | } 53 | } 54 | void end() { 55 | close(); 56 | } 57 | void setClock (uint32_t dummy) {} 58 | inline byte endTransmission (bool stop = true) { 59 | return I2cDev::endTransmission (stop) ? 0 : 4; 60 | } 61 | int requestFrom (uint16_t address, uint16_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop); 62 | inline int requestFrom (uint16_t slave, uint16_t max, bool stop = true) { 63 | return Piduino::I2cDev::requestFrom (slave, max, stop); 64 | } 65 | inline int requestFrom (int slave, int max, int stop = 1) { 66 | return Piduino::I2cDev::requestFrom (slave, max, stop); 67 | } 68 | }; 69 | 70 | extern TwoWire Wire; 71 | #endif 72 | -------------------------------------------------------------------------------- /include/piduino/board.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_BOARD_H 19 | #define PIDUINO_BOARD_H 20 | 21 | #include 22 | 23 | /** 24 | * @defgroup piduino_board Board 25 | * 26 | * Ce module fournit informations concernant la carte cible. 27 | * @{ 28 | */ 29 | 30 | namespace Piduino { 31 | } 32 | /** 33 | * @} 34 | */ 35 | 36 | /* ========================================================================== */ 37 | #endif /*PIDUINO_BOARD_H defined */ 38 | -------------------------------------------------------------------------------- /include/piduino/converter.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_CONVERTER_H 19 | #define PIDUINO_CONVERTER_H 20 | 21 | #include 22 | #include 23 | 24 | /** 25 | * @defgroup piduino_converter A/D or D/A Converter 26 | * @{ 27 | */ 28 | 29 | namespace Piduino { 30 | 31 | class Converter : public IoDevice { 32 | 33 | public: 34 | enum Type { 35 | AnalogToDigital, 36 | DigitalToAnalog, 37 | None = -1 38 | }; 39 | 40 | Converter(); 41 | virtual ~Converter(); 42 | 43 | Type type() const; 44 | virtual bool bipolar() const; 45 | virtual int resolution() const; 46 | virtual int setResolution (int resolution) { return -1; } 47 | virtual long max() const; 48 | virtual long min() const; 49 | 50 | virtual bool open (IoDevice::OpenMode mode = IoDevice::ReadWrite); 51 | virtual void close(); 52 | virtual long read(); 53 | virtual bool write (long value); 54 | virtual void setEnable (bool enable) { /* do nothing */ } 55 | virtual bool isEnabled () const { return true; } 56 | inline void run() { setEnable (true); } 57 | inline void stop() { setEnable (false); } 58 | 59 | virtual const std::string & deviceName() const; 60 | 61 | protected: 62 | class Private; 63 | Converter (Private &dd); 64 | 65 | private: 66 | PIMP_DECLARE_PRIVATE (Converter) 67 | }; 68 | } 69 | /** 70 | * @} 71 | */ 72 | 73 | /* ========================================================================== */ 74 | #endif /*PIDUINO_CONVERTER_H defined */ 75 | -------------------------------------------------------------------------------- /include/piduino/fileno.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * Copyright © 2010-2016 Stephen Kell, https://github.com/stephenrkell 3 | * Copyright © 2005 Richard Kreckel, https://www.ginac.de/~kreckel 4 | * This file is part of the Piduino Library. 5 | * 6 | * Stephen Kell's distribution of Richard Kreckel's fileno() function for 7 | * popular implementations of the C++ standard library. 8 | * 9 | * The Piduino Library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 3 of the License, or (at your option) any later version. 13 | * 14 | * The Piduino Library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with the Piduino Library; if not, see . 21 | */ 22 | #ifndef PIDUINO_FILENO_H 23 | #define PIDUINO_FILENO_H 24 | 25 | #include 26 | 27 | namespace Piduino { 28 | 29 | /** 30 | * @brief Map a stream pointer to a file descriptor 31 | * 32 | * Returns the integer file descriptor associated with the C++ stream pointed to by stream. 33 | */ 34 | template 35 | int fileno (const std::basic_ios& stream); 36 | } 37 | 38 | /* ========================================================================== */ 39 | #endif /*PIDUINO_FILENO_H defined */ 40 | -------------------------------------------------------------------------------- /include/piduino/gpiodevice.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace Piduino { 23 | 24 | /* 25 | @class GpioDevice 26 | @author Pascal JEAN 27 | @date 02/22/18 28 | @brief Accès à la couche matérielle du GPIO 29 | 30 | Classe abstraite devant être implémentée sur la plateforme cible. 31 | */ 32 | class GpioDevice { 33 | 34 | public: 35 | enum { 36 | hasToggle = 0x0001, 37 | hasPullRead = 0x0002, 38 | hasAltRead = 0x0004, 39 | hasDrive = 0x0008 40 | }; 41 | 42 | GpioDevice(); 43 | virtual ~GpioDevice(); 44 | virtual bool isOpen() const; 45 | virtual bool isDebug() const; 46 | virtual void setDebug (bool enable); 47 | virtual unsigned int flags() const; 48 | 49 | virtual bool open() = 0; 50 | virtual void close() = 0; 51 | virtual AccessLayer preferedAccessLayer() const = 0; 52 | 53 | virtual void setMode (const Pin *pin, Pin::Mode m) = 0; 54 | virtual void setPull (const Pin *pin, Pin::Pull p) = 0; 55 | virtual void write (const Pin *pin, bool v) = 0; 56 | virtual void toggle (const Pin *pin); 57 | 58 | virtual bool read (const Pin *pin) const = 0; 59 | virtual Pin::Mode mode (const Pin *pin) const = 0; 60 | virtual Pin::Pull pull (const Pin *pin) const; 61 | 62 | virtual void setDrive (const Pin *pin, int d); 63 | virtual int drive (const Pin *pin) const; 64 | 65 | virtual const std::map &modes() const = 0; 66 | virtual int systemNumberOffset() const; 67 | 68 | protected: 69 | class Private; 70 | GpioDevice (Private &dd); 71 | std::unique_ptr d_ptr; 72 | 73 | private: 74 | PIMP_DECLARE_PRIVATE (GpioDevice) 75 | }; 76 | } 77 | /* ========================================================================== */ 78 | -------------------------------------------------------------------------------- /include/piduino/gpiopwm.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_GPIOPWM_H 19 | #define PIDUINO_GPIOPWM_H 20 | 21 | #include 22 | #include 23 | 24 | /** 25 | * @defgroup piduino_gpiopwm GPIO PWM generator 26 | * @{ 27 | */ 28 | 29 | namespace Piduino { 30 | 31 | class GpioPwm : public Pwm { 32 | 33 | public: 34 | GpioPwm (Pin * pin, unsigned int resolution = 10, unsigned long freq = 100); 35 | virtual ~GpioPwm(); 36 | 37 | const Pin & pin() const; 38 | virtual long frequency() const; 39 | 40 | virtual const std::string & deviceName() const; 41 | 42 | protected: 43 | class Private; 44 | GpioPwm (Private &dd); 45 | 46 | private: 47 | PIMP_DECLARE_PRIVATE (GpioPwm) 48 | }; 49 | } 50 | /** 51 | * @} 52 | */ 53 | 54 | /* ========================================================================== */ 55 | #endif /*PIDUINO_GPIOPWM_H defined */ 56 | -------------------------------------------------------------------------------- /include/piduino/manufacturer.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_MANUFACTURER_H 19 | #define PIDUINO_MANUFACTURER_H 20 | 21 | #include 22 | 23 | /** 24 | * @defgroup piduino_manufacturer Fabricants 25 | * 26 | * Ce module fournit informations concernant les fabricants 27 | * @{ 28 | */ 29 | 30 | namespace Piduino { 31 | 32 | class Manufacturer { 33 | public: 34 | 35 | enum Id { 36 | Broadcom = 0, 37 | SonyUK, 38 | Qisda, 39 | Egoman, 40 | Embest, 41 | Allwinner, 42 | FriendlyARM, 43 | Stadium, 44 | SonyJapan, 45 | // Add New item here and update manufactuer table in database ! 46 | 47 | //--- 48 | Unknown = -1 49 | }; 50 | 51 | Manufacturer (Id i = Unknown) { 52 | setId (i); 53 | } 54 | virtual ~Manufacturer() {} 55 | 56 | inline Id id() const { 57 | return _id; 58 | } 59 | 60 | inline const std::string &name() const { 61 | return _name; 62 | } 63 | 64 | void setId (Id i); 65 | 66 | private: 67 | Id _id; 68 | std::string _name; 69 | }; 70 | } 71 | /** 72 | * @} 73 | */ 74 | 75 | /* ========================================================================== */ 76 | #endif /*PIDUINO_MANUFACTURER_H defined */ 77 | -------------------------------------------------------------------------------- /include/piduino/memory.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_MEMORY_H 19 | #define PIDUINO_MEMORY_H 20 | 21 | #include 22 | 23 | #ifndef __cpp_lib_make_unique 24 | // defined make_unique if < c++14 25 | #include 26 | #include 27 | #include 28 | 29 | namespace std { 30 | template struct _Unique_if { 31 | typedef unique_ptr _Single_object; 32 | }; 33 | 34 | template struct _Unique_if { 35 | typedef unique_ptr _Unknown_bound; 36 | }; 37 | 38 | template struct _Unique_if { 39 | typedef void _Known_bound; 40 | }; 41 | 42 | template 43 | typename _Unique_if::_Single_object 44 | make_unique (Args && ... args) { 45 | return unique_ptr (new T (std::forward (args)...)); 46 | } 47 | 48 | template 49 | typename _Unique_if::_Unknown_bound 50 | make_unique (size_t n) { 51 | typedef typename remove_extent::type U; 52 | return unique_ptr (new U[n]()); 53 | } 54 | 55 | template 56 | typename _Unique_if::_Known_bound 57 | make_unique (Args && ...) = delete; 58 | } 59 | #endif /* __cpp_lib_make_unique not defined */ 60 | 61 | /* ========================================================================== */ 62 | #endif /* PIDUINO_MEMORY_H defined */ 63 | -------------------------------------------------------------------------------- /include/piduino/pwm.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_PWM_H 19 | #define PIDUINO_PWM_H 20 | 21 | #include 22 | 23 | /** 24 | * @defgroup piduino_pwm PWM generator 25 | * @{ 26 | */ 27 | 28 | namespace Piduino { 29 | 30 | class Pwm : public Converter { 31 | 32 | public: 33 | Pwm (); 34 | virtual ~Pwm(); 35 | virtual long frequency() const = 0; 36 | virtual bool setFrequency (long freq) const { return false; } 37 | virtual long range() const { return (1L << resolution()); } 38 | virtual long setRange (long range) { return -1; } 39 | 40 | protected: 41 | class Private; 42 | Pwm (Private &dd); 43 | 44 | private: 45 | PIMP_DECLARE_PRIVATE (Pwm) 46 | }; 47 | } 48 | /** 49 | * @} 50 | */ 51 | 52 | /* ========================================================================== */ 53 | #endif /*PIDUINO_PWM_H defined */ 54 | -------------------------------------------------------------------------------- /include/piduino/terminalnotifier.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef PIDUINO_TERMIONOTIFIER_H 18 | #define PIDUINO_TERMIONOTIFIER_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | /** 25 | * @defgroup piduino_terminalnotifier Read Notifier 26 | * @{ 27 | */ 28 | 29 | namespace Piduino { 30 | 31 | /** 32 | * @class TerminalNotifier 33 | * @brief 34 | */ 35 | class TerminalNotifier { 36 | public: 37 | TerminalNotifier (FileDevice * io); 38 | virtual ~TerminalNotifier(); 39 | 40 | bool start (); 41 | void terminate(); 42 | bool isRunning() const; 43 | 44 | size_t available() const; 45 | 46 | size_t read (char * buf, size_t len, long msTimeout = 0); 47 | size_t read (std::string & str, long msTimeout = 0); 48 | bool read (char & c, long msTimeout = 0); 49 | 50 | size_t peek (char * buf, size_t len, long msTimeout = 0); 51 | size_t peek (std::string & str, long msTimeout = 0); 52 | bool peek (char & c, long msTimeout = 0); 53 | 54 | protected: 55 | class Private; 56 | TerminalNotifier (Private &dd); 57 | std::shared_ptr d_ptr; 58 | 59 | private: 60 | PIMP_DECLARE_PRIVATE (TerminalNotifier) 61 | }; 62 | 63 | } 64 | /** 65 | * @} 66 | */ 67 | 68 | /* ========================================================================== */ 69 | #endif /* PIDUINO_TERMIONOTIFIER_H defined */ 70 | -------------------------------------------------------------------------------- /lib/config.h.in: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_CONFIG_H_ 19 | #define PIDUINO_CONFIG_H_ 20 | /* ========================================================================== */ 21 | #cmakedefine01 PIDUINO_WITH_ARDUINO 22 | #cmakedefine01 PIDUINO_WITH_GPIO 23 | #cmakedefine01 PIDUINO_WITH_I2C 24 | #cmakedefine01 PIDUINO_WITH_SPI 25 | #cmakedefine01 PIDUINO_WITH_STATIC 26 | #cmakedefine01 PIDUINO_DRIVER_BCM2835 27 | #cmakedefine01 PIDUINO_DRIVER_ALLWINNERH 28 | #cmakedefine HAVE_STRLCPY 29 | #cmakedefine HAVE_STRLCAT 30 | 31 | #define PIDUINO_VERSION "@PIDUINO_VERSION_STRING@" 32 | #define PIDUINO_VERSION_SHORT "@PIDUINO_VERSION_SHORT@" 33 | #define PIDUINO_VERSION_TINY "@PIDUINO_VERSION_TINY@" 34 | #define PIDUINO_VERSION_MAJOR @PIDUINO_VERSION_MAJOR@ 35 | #define PIDUINO_VERSION_MINOR @PIDUINO_VERSION_MINOR@ 36 | #define PIDUINO_VERSION_PATCH @PIDUINO_VERSION_PATCH@ 37 | #define PIDUINO_VERSION_SHA1 @PIDUINO_VERSION_SHA1@ 38 | 39 | /* ========================================================================== */ 40 | #endif /*PIDUINO_CONFIG_H_ defined */ 41 | -------------------------------------------------------------------------------- /lib/piduino-config-version.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Pascal JEAN, All rights reserved. 2 | # This file is part of the Piduino Project. 3 | # 4 | # The Piduino Project is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # The Piduino Project is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with the Piduino Project. If not, see . 16 | set(PACKAGE_VERSION "@PIDUINO_VERSION@") 17 | 18 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 19 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 20 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 21 | else() 22 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 23 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 24 | set(PACKAGE_VERSION_EXACT TRUE) 25 | endif() 26 | endif() 27 | -------------------------------------------------------------------------------- /lib/piduino.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | bindir=@INSTALL_BIN_DIR@ 4 | libdir=@INSTALL_LIB_DIR@ 5 | includedir=@INSTALL_INCLUDE_DIR@ 6 | ldflags_other=@PIDUINO_LDFLAGS_PKGCONFIG@ 7 | cflags_other=@PIDUINO_CFLAGS_PKGCONFIG@ 8 | 9 | Name: @PROJECT_NAME@ 10 | Description: @PROJECT_DESCRIPTION@ 11 | URL: https://github.com/epsilonrt/piduino 12 | Version: @PIDUINO_VERSION@ 13 | Requires: 14 | Libs: -L${libdir} -lpiduino ${ldflags_other} 15 | Cflags: -I${includedir} -I${includedir}/piduino/arduino ${cflags_other} 16 | 17 | -------------------------------------------------------------------------------- /piduino.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/arch/arm/allwinner/gpio_hx.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace Piduino { 22 | 23 | // ------------------------------------------------------------------------- 24 | // 25 | // AllWinnerHxGpio Class 26 | // 27 | // ------------------------------------------------------------------------- 28 | class AllWinnerHxGpio : public GpioDevice { 29 | 30 | public: 31 | AllWinnerHxGpio(); 32 | virtual ~AllWinnerHxGpio(); 33 | 34 | bool open(); 35 | void close(); 36 | AccessLayer preferedAccessLayer() const; 37 | unsigned int flags() const; 38 | 39 | void setMode (const Pin *pin, Pin::Mode m); 40 | void setPull (const Pin *pin, Pin::Pull p); 41 | void write (const Pin *pin, bool v); 42 | void toggle (const Pin *pin); 43 | 44 | bool read (const Pin *pin) const; 45 | Pin::Mode mode (const Pin *pin) const; 46 | Pin::Pull pull (const Pin *pin) const; 47 | void setDrive (const Pin *pin, int d); 48 | int drive (const Pin *pin) const; 49 | 50 | const std::map &modes() const; 51 | 52 | protected: 53 | class Private; 54 | AllWinnerHxGpio (Private &dd); 55 | 56 | private: 57 | PIMP_DECLARE_PRIVATE (AllWinnerHxGpio) 58 | }; 59 | } 60 | /* ========================================================================== */ 61 | -------------------------------------------------------------------------------- /src/arch/arm/allwinner/gpio_hx_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include "hx.h" 21 | #include "gpio_hx.h" 22 | #include "../../../gpio/gpiodevice_p.h" 23 | 24 | namespace Piduino { 25 | 26 | class AllWinnerHxGpio::Private : public GpioDevice::Private { 27 | public: 28 | Private (AllWinnerHxGpio *q); 29 | virtual ~Private(); 30 | 31 | /* 32 | H3/H5 PIO Registers: 33 | Module Base Address Port 34 | PIO1 0x01C20800 A,B,C,D,E,F,G (n=0 to n=6, n=1 no pin) 35 | PIO2 0x01F02C00 L (n=0) 36 | 37 | Register Offset Description 38 | Pn_CFG0 0x0000 + n*0x24 Port n Configure Register 0 (n from 0 to 6) 39 | Pn_CFG1 0x0004 + n*0x24 Port n Configure Register 1 (n from 0 to 6) 40 | Pn_CFG2 0x0008 + n*0x24 Port n Configure Register 2 (n from 0 to 6) 41 | Pn_CFG3 0x000C + n*0x24 Port n Configure Register 3 (n from 0 to 6) 42 | Pn_DAT 0x0010 + n*0x24 Port n Data Register (n from 0 to 6) 43 | Pn_DRV0 0x0014 + n*0x24 Port n Multi-Driving Register 0 (n from 0 to 6) 44 | Pn_DRV1 0x0018 + n*0x24 Port n Multi-Driving Register 1 (n from 0 to 6) 45 | Pn_PUL0 0x001C + n*0x24 Port n Pull Register 0 (n from 0 to 6) 46 | Pn_PUL1 0x0020 + n*0x24 Port n Pull Register 1 (n from 0 to 6) 47 | */ 48 | struct __attribute__ ( (__packed__)) PioBank { 49 | uint32_t CFG[4]; 50 | uint32_t DAT; 51 | uint32_t DRV[2]; 52 | uint32_t PUL[2]; 53 | }; 54 | typedef struct PioBank PioBank; 55 | 56 | void debugPrintBank (const PioBank *b) const; 57 | void debugPrintAllBanks () const; 58 | PioBank *pinBank (int *mcupin) const; 59 | PioBank *bank (unsigned int bkindex) const; 60 | 61 | IoMap iomap[2]; 62 | static const int portSize[]; 63 | static const std::map int2mode; 64 | static const std::map mode2int; 65 | static const std::map modes; 66 | 67 | PIMP_DECLARE_PUBLIC (AllWinnerHxGpio) 68 | }; 69 | } -------------------------------------------------------------------------------- /src/arch/arm/allwinner/pwm_hx.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef PIDUINO_ARCH_ARM_ALLWINNER_PWM_HX_H 18 | #define PIDUINO_ARCH_ARM_ALLWINNER_PWM_HX_H 19 | #include 20 | #include 21 | #include "hx.h" 22 | 23 | namespace Piduino { 24 | 25 | namespace AllWinnerHx { 26 | 27 | /** 28 | * @class AllWinnerHx::PwmEngine 29 | * @brief 30 | */ 31 | class PwmEngine : public SocPwm::Engine { 32 | 33 | public: 34 | PwmEngine (SocPwm::Private * d, Pin * p); 35 | ~PwmEngine(); 36 | 37 | bool open (IoDevice::OpenMode mode); 38 | void close(); 39 | const std::string & deviceName() const; 40 | 41 | // isOpen() checked before calling this functions 42 | long frequency() const; 43 | int resolution() const; 44 | long range() const; 45 | long max() const; 46 | long min() const; 47 | bool setFrequency (long freq); 48 | bool setResolution (int resolution); 49 | bool setRange (long range); 50 | 51 | // hasPin() checked before calling this functions 52 | long read(); 53 | bool write (long value); 54 | void setEnable (bool enable); 55 | bool isEnabled () const; 56 | 57 | private: 58 | IoMap pwm; 59 | size_t periodReg; 60 | int timeout_us; 61 | 62 | uint32_t period() const; 63 | bool setPeriod (uint32_t period); 64 | uint16_t value() const; 65 | bool setValue (uint16_t v); 66 | 67 | unsigned long clockDivisor() const; 68 | void setClockDivisor (unsigned long div); 69 | unsigned long frequencyDivisor (long freq); 70 | long divisorFrequency (unsigned long divisor); 71 | unsigned long findValidDivisor (unsigned long div); 72 | 73 | void writeReg (size_t offset, uint32_t value); 74 | uint32_t readReg (size_t offset) const; 75 | }; 76 | } 77 | } 78 | 79 | /* ========================================================================== */ 80 | #endif /* PIDUINO_ARCH_ARM_ALLWINNER_PWM_HX_H defined */ 81 | -------------------------------------------------------------------------------- /src/arch/arm/broadcom/bcm2835.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #include 18 | #include 19 | #include "bcm2835.h" 20 | #include "config.h" 21 | 22 | namespace Piduino { 23 | 24 | namespace Bcm2835 { 25 | 26 | // ------------------------------------------------------------------------- 27 | off_t iobase () { 28 | static const std::map list { 29 | {SoC::Bcm2708, Bcm2708Base}, 30 | {SoC::Bcm2709, Bcm2709Base}, 31 | {SoC::Bcm2710, Bcm2710Base}, 32 | {SoC::Bcm2711, Bcm2711Base}, 33 | }; 34 | 35 | if (db.board().soc().family().id() != SoC::Family::BroadcomBcm2835) { 36 | 37 | throw std::system_error (ENOTSUP, std::system_category(), 38 | "It seems that this system is not a Broadcom BCM2835 board !"); 39 | } 40 | return list.at (db.board().soc().id()); 41 | } 42 | } 43 | } 44 | /* ========================================================================== */ 45 | -------------------------------------------------------------------------------- /src/arch/arm/broadcom/gpio_bcm2835.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace Piduino { 22 | 23 | // ------------------------------------------------------------------------- 24 | // 25 | // Bcm2835Gpio Class 26 | // 27 | // ------------------------------------------------------------------------- 28 | class Bcm2835Gpio : public GpioDevice { 29 | 30 | public: 31 | Bcm2835Gpio(); 32 | virtual ~Bcm2835Gpio(); 33 | 34 | bool open(); 35 | void close(); 36 | AccessLayer preferedAccessLayer() const; 37 | unsigned int flags() const; 38 | 39 | void setMode (const Pin *pin, Pin::Mode m); 40 | void setPull (const Pin *pin, Pin::Pull p); 41 | void write (const Pin *pin, bool v); 42 | 43 | bool read (const Pin *pin) const; 44 | Pin::Mode mode (const Pin *pin) const; 45 | Pin::Pull pull (const Pin *pin) const; 46 | int systemNumberOffset() const; 47 | 48 | const std::map &modes() const; 49 | 50 | protected: 51 | class Private; 52 | Bcm2835Gpio (Private &dd); 53 | 54 | private: 55 | PIMP_DECLARE_PRIVATE (Bcm2835Gpio) 56 | }; 57 | } 58 | /* ========================================================================== */ 59 | -------------------------------------------------------------------------------- /src/arch/arm/broadcom/gpio_bcm2835_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include "bcm2835.h" 21 | #include "gpio_bcm2835.h" 22 | #include "../../../gpio/gpiodevice_p.h" 23 | 24 | namespace Piduino { 25 | 26 | class Bcm2835Gpio::Private : public GpioDevice::Private { 27 | 28 | public: 29 | Private (Bcm2835Gpio *q); 30 | virtual ~Private(); 31 | 32 | off_t piobase; 33 | IoMap iomap; 34 | 35 | inline uint32_t readReg (size_t offset) const { 36 | return *iomap.io (offset); 37 | } 38 | 39 | inline void writeReg (size_t offset, uint32_t value) { 40 | *iomap.io (offset) = value; 41 | } 42 | 43 | static const std::map int2mode; 44 | static const std::map mode2int; 45 | static const std::map modes; 46 | static bool is2711; 47 | static int systemNumberOffset; 48 | 49 | PIMP_DECLARE_PUBLIC (Bcm2835Gpio) 50 | }; 51 | } -------------------------------------------------------------------------------- /src/arduino/Console.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | 23 | // ----------------------------------------------------------------------------- 24 | PiConsole::PiConsole() : _keyb(STDIN_FILENO), _notifier(&_keyb) { 25 | 26 | } 27 | 28 | // ----------------------------------------------------------------------------- 29 | void PiConsole::begin (__attribute__ ( (__unused__)) unsigned long, 30 | __attribute__ ( (__unused__)) uint8_t) { 31 | 32 | Terminal::begin(); 33 | _notifier.start (); 34 | } 35 | 36 | // ----------------------------------------------------------------------------- 37 | void PiConsole::end () { 38 | 39 | _notifier.terminate(); 40 | Terminal::end(); 41 | } 42 | 43 | // ----------------------------------------------------------------------------- 44 | ostream & PiConsole::os() { 45 | 46 | return cout; 47 | } 48 | 49 | // ----------------------------------------------------------------------------- 50 | Piduino::TerminalNotifier & PiConsole::notifier() { 51 | 52 | return _notifier; 53 | } 54 | 55 | /* ========================================================================== */ 56 | -------------------------------------------------------------------------------- /src/arduino/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 | 3 | /* 4 | Part of the Wiring project - http://wiring.org.co 5 | Copyright (c) 2004-06 Hernando Barragan 6 | Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/ 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General 19 | Public License along with this library; if not, write to the 20 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 21 | Boston, MA 02111-1307 USA 22 | */ 23 | 24 | extern "C" { 25 | #include "stdlib.h" 26 | } 27 | 28 | void randomSeed (unsigned long seed) { 29 | if (seed != 0) { 30 | srandom (seed); 31 | } 32 | } 33 | 34 | long random (long howbig) { 35 | if (howbig == 0) { 36 | return 0; 37 | } 38 | return random() % howbig; 39 | } 40 | 41 | long random (long howsmall, long howbig) { 42 | if (howsmall >= howbig) { 43 | return howsmall; 44 | } 45 | long diff = howbig - howsmall; 46 | return random (diff) + howsmall; 47 | } 48 | 49 | long map (long x, long in_min, long in_max, long out_min, long out_max) { 50 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 51 | } 52 | 53 | unsigned int makeWord (unsigned int w) { 54 | return w; 55 | } 56 | unsigned int makeWord (unsigned char h, unsigned char l) { 57 | return (h << 8) | l; 58 | } 59 | -------------------------------------------------------------------------------- /src/arduino/compat/strlcat_strlcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "config.h" 3 | 4 | #ifndef HAVE_STRLCAT 5 | /* 6 | * '_cups_strlcat()' - Safely concatenate two strings. 7 | */ 8 | size_t /* O - Length of string */ 9 | strlcat (char *dst, /* O - Destination string */ 10 | const char *src, /* I - Source string */ 11 | size_t size) { /* I - Size of destination string buffer */ 12 | size_t srclen; /* Length of source string */ 13 | size_t dstlen; /* Length of destination string */ 14 | 15 | 16 | /* 17 | * Figure out how much room is left... 18 | */ 19 | 20 | dstlen = strlen (dst); 21 | size -= dstlen + 1; 22 | 23 | if (!size) { 24 | return (dstlen); /* No room, return immediately... */ 25 | } 26 | 27 | /* 28 | * Figure out how much room is needed... 29 | */ 30 | 31 | srclen = strlen (src); 32 | 33 | /* 34 | * Copy the appropriate amount... 35 | */ 36 | 37 | if (srclen > size) { 38 | srclen = size; 39 | } 40 | 41 | memcpy (dst + dstlen, src, srclen); 42 | dst[dstlen + srclen] = '\0'; 43 | 44 | return (dstlen + srclen); 45 | } 46 | #endif /* !HAVE_STRLCAT */ 47 | 48 | #ifndef HAVE_STRLCPY 49 | /* 50 | * '_cups_strlcpy()' - Safely copy two strings. 51 | */ 52 | size_t /* O - Length of string */ 53 | strlcpy (char *dst, /* O - Destination string */ 54 | const char *src, /* I - Source string */ 55 | size_t size) { /* I - Size of destination string buffer */ 56 | size_t srclen; /* Length of source string */ 57 | 58 | 59 | /* 60 | * Figure out how much room is needed... 61 | */ 62 | 63 | size --; 64 | 65 | srclen = strlen (src); 66 | 67 | /* 68 | * Copy the appropriate amount... 69 | */ 70 | 71 | if (srclen > size) { 72 | srclen = size; 73 | } 74 | 75 | memcpy (dst, src, srclen); 76 | dst[srclen] = '\0'; 77 | 78 | return (srclen); 79 | } 80 | #endif /* !HAVE_STRLCPY */ 81 | -------------------------------------------------------------------------------- /src/arduino/i2c/Wire.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.cpp - TWI/I2C library for Wiring & Arduino 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | Modified 2018 by Pascal JEAN (pascal.jean@piduino.org) for piduino library 21 | */ 22 | #include 23 | 24 | // Public Methods ////////////////////////////////////////////////////////////// 25 | int TwoWire::requestFrom (uint16_t address, uint16_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop) { 26 | 27 | if (isize > 0) { 28 | // send internal address; this mode allows sending a repeated start to access 29 | // some devices' internal registers. This function is executed by the hardware 30 | // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers) 31 | 32 | beginTransmission (address); 33 | 34 | // the maximum size of internal address is 3 bytes 35 | if (isize > 3) { 36 | isize = 3; 37 | } 38 | 39 | // write internal register address - most significant byte first 40 | while (isize-- > 0) { 41 | write ( (uint8_t) (iaddress >> (isize * 8))); 42 | } 43 | endTransmission (false); 44 | } 45 | 46 | // clamp to buffer length 47 | if (quantity > BUFFER_LENGTH) { 48 | quantity = BUFFER_LENGTH; 49 | } 50 | 51 | // perform blocking read into buffer 52 | return I2cDev::requestFrom (address, quantity, sendStop != 0); 53 | } 54 | 55 | TwoWire Wire; 56 | -------------------------------------------------------------------------------- /src/board.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include "config.h" 21 | 22 | namespace Piduino { 23 | } 24 | 25 | /* ========================================================================== */ 26 | -------------------------------------------------------------------------------- /src/converter_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_CONVERTER_PRIVATE_H 19 | #define PIDUINO_CONVERTER_PRIVATE_H 20 | 21 | #include 22 | #include "iodevice_p.h" 23 | 24 | namespace Piduino { 25 | 26 | /** 27 | * @class Converter::Private 28 | * @brief 29 | */ 30 | class Converter::Private : public IoDevice::Private { 31 | 32 | public: 33 | Private (Converter * q, Type type = None, unsigned int resolution = 8, bool bipolar = false); 34 | virtual ~Private(); 35 | 36 | virtual bool open (OpenMode mode); 37 | virtual void close(); 38 | virtual long read(); 39 | virtual bool write (long value); 40 | virtual long max() const; 41 | virtual long min() const; 42 | 43 | Type type; 44 | bool bipolar; 45 | unsigned int resolution; 46 | 47 | PIMP_DECLARE_PUBLIC (Converter) 48 | }; 49 | } 50 | 51 | /* ========================================================================== */ 52 | #endif /* PIDUINO_CONVERTER_PRIVATE_H defined */ 53 | -------------------------------------------------------------------------------- /src/dummy.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/epsilonrt/piduino/4dd7aab6402c5e35325073dd1d4bfd21dcfa2e63/src/dummy.cpp -------------------------------------------------------------------------------- /src/filedevice_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_FILEDEVICE_PRIVATE_H 19 | #define PIDUINO_FILEDEVICE_PRIVATE_H 20 | 21 | #include 22 | #include "iodevice_p.h" 23 | 24 | namespace Piduino { 25 | 26 | /** 27 | * @class FileDevice::Private 28 | * @brief 29 | */ 30 | class FileDevice::Private : public IoDevice::Private { 31 | 32 | public: 33 | Private (FileDevice * q); 34 | virtual ~Private(); 35 | 36 | virtual bool open (OpenMode mode, int additionalPosixFlags = 0); 37 | virtual void close(); 38 | 39 | virtual int ioctl (int req); 40 | virtual int ioctl (int req, void *); 41 | 42 | int fd; 43 | bool ourFile; 44 | std::string path; 45 | 46 | PIMP_DECLARE_PUBLIC (FileDevice) 47 | }; 48 | } 49 | 50 | /* ========================================================================== */ 51 | #endif /* PIDUINO_FILEDEVICE_PRIVATE_H defined */ 52 | -------------------------------------------------------------------------------- /src/filestream_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_FILESTREAM_PRIVATE_H 19 | #define PIDUINO_FILESTREAM_PRIVATE_H 20 | 21 | #include 22 | #include 23 | #include "filedevice_p.h" 24 | 25 | namespace Piduino { 26 | 27 | /** 28 | * @class FileStream::Private 29 | * @brief 30 | */ 31 | class FileStream::Private : public FileDevice::Private { 32 | 33 | public: 34 | Private (FileStream * q); 35 | 36 | virtual bool open (OpenMode mode, int additionalPosixFlags = 0); 37 | virtual void close(); 38 | 39 | __gnu_cxx::stdio_filebuf iosbuf; 40 | 41 | PIMP_DECLARE_PUBLIC (FileStream) 42 | }; 43 | } 44 | 45 | /* ========================================================================== */ 46 | #endif /* PIDUINO_FILESTREAM_PRIVATE_H defined */ 47 | -------------------------------------------------------------------------------- /src/gpio/gpio_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | This file is part of the Piduino Library. 3 | 4 | The Piduino Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 3 of the License, or (at your option) any later version. 8 | 9 | The Piduino Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace Piduino { 22 | 23 | class Gpio::Private { 24 | 25 | public: 26 | Private (Gpio *q, long long gpioDatabaseId, SoC::Family::Id socFamilyId, AccessLayer layer); 27 | virtual ~Private(); 28 | 29 | Gpio *const q_ptr; 30 | bool roc; // Release On Close 31 | bool isopen; 32 | AccessLayer accesslayer; 33 | GpioDevice *device; // Accès à la couche matérielle 34 | Pin::Numbering numbering; // Numérotation en cours 35 | std::shared_ptr descriptor; 36 | std::map> pin; // Broches uniquement GPIO 37 | std::map> connector; // Connecteurs avec toutes les broches physiques 38 | 39 | PIMP_DECLARE_PUBLIC (Gpio) 40 | }; 41 | } 42 | 43 | /* ========================================================================== */ 44 | -------------------------------------------------------------------------------- /src/gpio/gpioconnector_p.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Piduino { 7 | namespace ConnectorOstream { 8 | 9 | // --------------------------------------------------------------------------- 10 | enum Alignment { 11 | Left, 12 | Right, 13 | Center 14 | }; 15 | 16 | // --------------------------------------------------------------------------- 17 | class Field { 18 | public: 19 | std::string::size_type size; 20 | std::string name; 21 | 22 | Field (std::string::size_type s, const std::string &n) : size (s), name (n) {} 23 | }; 24 | 25 | std::string toUpper (const std::string &s); 26 | std::string format (const std::string &s, std::string::size_type w, Alignment a); 27 | } 28 | } -------------------------------------------------------------------------------- /src/gpio/gpiodevice_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018-2025 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace Piduino { 22 | 23 | class GpioDevice::Private { 24 | 25 | public: 26 | Private (GpioDevice * q); 27 | virtual ~Private(); 28 | 29 | GpioDevice * const q_ptr; 30 | bool isopen; 31 | bool isdebug; 32 | 33 | PIMP_DECLARE_PUBLIC (GpioDevice) 34 | }; 35 | } 36 | 37 | /* ========================================================================== */ 38 | -------------------------------------------------------------------------------- /src/gpio/gpiopwm_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_GPIOPWM_PRIVATE_H 19 | #define PIDUINO_GPIOPWM_PRIVATE_H 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "pwm_p.h" 26 | 27 | namespace Piduino { 28 | 29 | /** 30 | * @class GpioPwm::Private 31 | * @brief 32 | */ 33 | class GpioPwm::Private : public Pwm::Private { 34 | 35 | public: 36 | Private (GpioPwm * q, Pin * pin, unsigned int resolution, unsigned long freq); 37 | virtual ~Private(); 38 | 39 | virtual bool open (OpenMode mode); 40 | virtual bool isOpen() const; 41 | virtual void close(); 42 | virtual long read(); 43 | virtual bool write (long value); 44 | 45 | Pin * pin; 46 | long value; 47 | long freq; 48 | std::atomic flag; // communication avec le thread 49 | std::thread thread; 50 | 51 | static const int FlagRun = 1; 52 | static const int FlagValueUpdated = 2; 53 | static void * generator (std::atomic & flag, GpioPwm::Private * d); 54 | 55 | PIMP_DECLARE_PUBLIC (GpioPwm) 56 | }; 57 | } 58 | 59 | /* ========================================================================== */ 60 | #endif /* PIDUINO_GPIOPWM_PRIVATE_H defined */ 61 | -------------------------------------------------------------------------------- /src/gpio/socpwm_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_SOCPWM_PRIVATE_H 19 | #define PIDUINO_SOCPWM_PRIVATE_H 20 | 21 | #include 22 | #include "pwm_p.h" 23 | 24 | namespace Piduino { 25 | 26 | /** 27 | * @class SocPwm::Private 28 | * @brief 29 | */ 30 | class SocPwm::Private : public Pwm::Private { 31 | 32 | public: 33 | // SocPwm::Private 34 | Private (SocPwm * q, Pin * pin); 35 | virtual ~Private(); 36 | bool hasEngine() const; 37 | bool hasPin() const; 38 | 39 | // IoDevice::Private 40 | virtual bool isOpen() const; 41 | 42 | // Converter::Private 43 | virtual bool open (OpenMode mode); 44 | virtual void close(); 45 | virtual long read(); 46 | virtual bool write (long value); 47 | virtual long max() const; 48 | virtual long min() const; 49 | 50 | // SocPwm::Private 51 | std::unique_ptr engine; 52 | 53 | PIMP_DECLARE_PUBLIC (SocPwm) 54 | }; 55 | } 56 | 57 | /* ========================================================================== */ 58 | #endif /* PIDUINO_SOCPWM_PRIVATE_H defined */ 59 | -------------------------------------------------------------------------------- /src/i2c/i2cdev_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * I2cDev is a modified and simplified version of QIODevice, 5 | * from Qt according to the LGPL and Copyright (C) 2015 The Qt Company Ltd. 6 | * 7 | * The Piduino Library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 3 of the License, or (at your option) any later version. 11 | * 12 | * The Piduino Library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with the Piduino Library; if not, see . 19 | */ 20 | 21 | #ifndef PIDUINO_I2CDEV_PRIVATE_H 22 | #define PIDUINO_I2CDEV_PRIVATE_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include "iodevice_p.h" 28 | 29 | #ifndef I2C_BLOCK_MAX 30 | #define I2C_BLOCK_MAX I2C_SMBUS_BLOCK_MAX 31 | #endif 32 | 33 | namespace Piduino { 34 | 35 | class I2cDev::Private : public IoDevice::Private { 36 | 37 | public: 38 | enum { 39 | Idle = 0, 40 | Write, 41 | Read 42 | }; 43 | 44 | Private (I2cDev * q); 45 | virtual ~Private(); 46 | bool transfer(); 47 | void flush(); 48 | 49 | int fd; 50 | int state; 51 | std::vector i2c_msgs; 52 | Fifo txbuf; 53 | Fifo rxbuf; 54 | Info bus; 55 | 56 | PIMP_DECLARE_PUBLIC (I2cDev) 57 | }; 58 | } 59 | /* ========================================================================== */ 60 | #endif /* PIDUINO_I2CDEV_PRIVATE_H defined */ 61 | -------------------------------------------------------------------------------- /src/iodevice_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_IODEVICE_PRIVATE_H 19 | #define PIDUINO_IODEVICE_PRIVATE_H 20 | 21 | #include 22 | #include 23 | 24 | namespace Piduino { 25 | 26 | class IoDevice::Private { 27 | 28 | public: 29 | Private (IoDevice * q); 30 | virtual ~Private(); 31 | 32 | virtual bool open (OpenMode mode); 33 | virtual void close(); 34 | virtual bool isOpen() const; 35 | 36 | virtual void clearError(); 37 | virtual void setError (); 38 | virtual void setError (int error); 39 | virtual void setError (int error, const std::string & errorString); 40 | 41 | static int modeToPosixFlags (OpenMode mode); 42 | 43 | IoDevice * const q_ptr; 44 | 45 | OpenMode openMode; 46 | bool isSequential; 47 | int error; 48 | std::string errorString; 49 | 50 | PIMP_DECLARE_PUBLIC (IoDevice) 51 | }; 52 | } 53 | 54 | /* ========================================================================== */ 55 | #endif /* PIDUINO_IODEVICE_PRIVATE_H defined */ 56 | -------------------------------------------------------------------------------- /src/manufacturer.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #include 18 | #include 19 | #include "config.h" 20 | 21 | namespace Piduino { 22 | 23 | // ----------------------------------------------------------------------------- 24 | // 25 | // Manufacturer Class 26 | // 27 | // ----------------------------------------------------------------------------- 28 | 29 | // ----------------------------------------------------------------------------- 30 | void Manufacturer::setId (Manufacturer::Id i) { 31 | 32 | cppdb::result res = db << "SELECT name FROM manufacturer WHERE id=?" << i << cppdb::row; 33 | if (!res.empty()) { 34 | 35 | _id = i; 36 | res >> _name; 37 | } 38 | } 39 | } 40 | /* ========================================================================== */ 41 | -------------------------------------------------------------------------------- /src/pwm.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #include "pwm_p.h" 18 | #include "config.h" 19 | 20 | namespace Piduino { 21 | 22 | // ----------------------------------------------------------------------------- 23 | // 24 | // Pwm Class 25 | // 26 | // ----------------------------------------------------------------------------- 27 | 28 | // --------------------------------------------------------------------------- 29 | Pwm::Pwm (Pwm::Private &dd) : Converter (dd) {} 30 | 31 | // --------------------------------------------------------------------------- 32 | Pwm::Pwm () : Converter (*new Private (this)) {} 33 | 34 | // --------------------------------------------------------------------------- 35 | Pwm::~Pwm() = default; 36 | 37 | // ----------------------------------------------------------------------------- 38 | // 39 | // Pwm::Private Class 40 | // 41 | // ----------------------------------------------------------------------------- 42 | 43 | // --------------------------------------------------------------------------- 44 | Pwm::Private::Private (Pwm * q) : 45 | Converter::Private (q, DigitalToAnalog) {} 46 | 47 | // --------------------------------------------------------------------------- 48 | Pwm::Private::~Private() = default; 49 | 50 | } 51 | 52 | /* ========================================================================== */ 53 | -------------------------------------------------------------------------------- /src/pwm_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #ifndef PIDUINO_PWM_PRIVATE_H 19 | #define PIDUINO_PWM_PRIVATE_H 20 | 21 | #include 22 | #include "converter_p.h" 23 | 24 | namespace Piduino { 25 | 26 | /** 27 | * @class Pwm::Private 28 | * @brief 29 | */ 30 | class Pwm::Private : public Converter::Private { 31 | 32 | public: 33 | Private (Pwm * q); 34 | virtual ~Private(); 35 | 36 | PIMP_DECLARE_PUBLIC (Pwm) 37 | }; 38 | } 39 | 40 | /* ========================================================================== */ 41 | #endif /* PIDUINO_PWM_PRIVATE_H defined */ 42 | -------------------------------------------------------------------------------- /src/scheduler.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "config.h" 22 | 23 | namespace Piduino { 24 | 25 | // ----------------------------------------------------------------------------- 26 | // 27 | // Scheduler Class 28 | // 29 | // ----------------------------------------------------------------------------- 30 | 31 | // ----------------------------------------------------------------------------- 32 | void Scheduler::setRtPriority (int priority) { 33 | struct sched_param sparam; 34 | int min, max; 35 | int policy; 36 | 37 | min = sched_get_priority_min (SCHED_FIFO); 38 | max = sched_get_priority_max (SCHED_FIFO); 39 | pthread_getschedparam (pthread_self(), &policy, &sparam); 40 | 41 | if (priority < min) { 42 | 43 | sparam.sched_priority = min; 44 | } 45 | if (priority > max) { 46 | 47 | sparam.sched_priority = max; 48 | } 49 | else { 50 | 51 | sparam.sched_priority = priority; 52 | } 53 | 54 | if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &sparam) < 0) { 55 | 56 | throw std::system_error (errno, std::system_category(), __FUNCTION__); 57 | } 58 | } 59 | 60 | // ----------------------------------------------------------------------------- 61 | int Scheduler::rtPriority() { 62 | struct sched_param sparam; 63 | int policy; 64 | 65 | pthread_getschedparam (pthread_self(), &policy, &sparam); 66 | return sparam.sched_priority; 67 | } 68 | 69 | // ----------------------------------------------------------------------------- 70 | int Scheduler::rtPriorityMin() { 71 | 72 | return sched_get_priority_min (SCHED_FIFO); 73 | } 74 | 75 | // ----------------------------------------------------------------------------- 76 | int Scheduler::rtPriorityMax() { 77 | 78 | return sched_get_priority_max (SCHED_FIFO); 79 | } 80 | 81 | // ----------------------------------------------------------------------------- 82 | void Scheduler::yield() { 83 | sched_yield(); 84 | } 85 | 86 | } 87 | /* ========================================================================== */ 88 | -------------------------------------------------------------------------------- /src/serial/serialportinfo_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * SerialPort is a modified and simplified version of QSerialPort, 5 | * from Qt according to the LGPL and Copyright (C) 2015 The Qt Company Ltd. 6 | * 7 | * The Piduino Library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 3 of the License, or (at your option) any later version. 11 | * 12 | * The Piduino Library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | */ 17 | #ifndef PIDUINO_SERIALPORTINFO_PRIVATE_H 18 | #define PIDUINO_SERIALPORTINFO_PRIVATE_H 19 | 20 | #include 21 | 22 | namespace Piduino { 23 | 24 | 25 | class SerialPort::Info::Private { 26 | 27 | public: 28 | Private (); 29 | static bool isValidSerialPort (const char * path); 30 | static bool isValid8250Device (const char * path); 31 | static uint16_t identifier (const char * value, bool & hasIdentifier); 32 | static std::string portIdToSystemLocation (int portId); 33 | 34 | std::string path; 35 | std::string name; 36 | std::string driver; 37 | std::string description; 38 | std::string manufacturer; 39 | std::string serialNumber; 40 | uint16_t vendorIdentifier; 41 | uint16_t productIdentifier; 42 | bool hasVendorIdentifier; 43 | bool hasProductIdentifier; 44 | }; 45 | 46 | } 47 | /* ========================================================================== */ 48 | #endif /* PIDUINO_SERIALPORTINFO_PRIVATE_H defined */ 49 | -------------------------------------------------------------------------------- /src/spi/spidev_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef PIDUINO_SPIDEV_PRIVATE_H 18 | #define PIDUINO_SPIDEV_PRIVATE_H 19 | 20 | #include 21 | #include "iodevice_p.h" 22 | 23 | namespace Piduino { 24 | 25 | class SpiDev::Private : public IoDevice::Private { 26 | 27 | public: 28 | 29 | Private (SpiDev * q); 30 | virtual ~Private(); 31 | 32 | int fd; 33 | Settings settings; 34 | Info bus; 35 | std::vector tstack; 36 | 37 | void setMode (); 38 | void setSpeedHz (); 39 | void setBitsPerWord (); 40 | void setBitOrder (); 41 | void setSettings (); 42 | void getMode (); 43 | void getSpeedHz (); 44 | void getBitsPerWord (); 45 | void getBitOrder (); 46 | void getSettings (); 47 | 48 | PIMP_DECLARE_PUBLIC (SpiDev) 49 | }; 50 | } 51 | /* ========================================================================== */ 52 | #endif /* PIDUINO_SPIDEV_PRIVATE_H defined */ 53 | -------------------------------------------------------------------------------- /src/terminal_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef PIDUINO_TERMINAL_PRIVATE_H 18 | #define PIDUINO_TERMINAL_PRIVATE_H 19 | 20 | #include 21 | #include "filestream_p.h" 22 | 23 | namespace Piduino { 24 | 25 | /** 26 | * @class Terminal::Private 27 | * @brief 28 | */ 29 | class Terminal::Private : public FileStream::Private { 30 | 31 | public: 32 | Private (Terminal * q); 33 | 34 | virtual bool open (OpenMode mode, int additionalPosixFlags = 0); 35 | virtual void close(); 36 | 37 | Piduino::TerminalNotifier notifier; 38 | 39 | PIMP_DECLARE_PUBLIC (Terminal) 40 | }; 41 | } 42 | 43 | /* ========================================================================== */ 44 | #endif /* PIDUINO_TERMINAL_PRIVATE_H defined */ 45 | -------------------------------------------------------------------------------- /src/terminalnotifier_p.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino Library. 3 | * 4 | * The Piduino Library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 3 of the License, or (at your option) any later version. 8 | * 9 | * The Piduino Library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License 15 | * along with the Piduino Library; if not, see . 16 | */ 17 | #ifndef PIDUINO_TERMIONOTIFIER_PRIVATE_H 18 | #define PIDUINO_TERMIONOTIFIER_PRIVATE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace Piduino { 28 | 29 | class TerminalNotifier::Private { 30 | public: 31 | 32 | Private (TerminalNotifier * q, FileDevice * iofile); 33 | virtual ~Private(); 34 | static void * readNotifier (std::future run, TerminalNotifier::Private * d); 35 | static int poll (int fd, unsigned long timeout_ms); 36 | 37 | TerminalNotifier * const q_ptr; 38 | FileDevice * io; 39 | struct termios pterm; 40 | ThreadSafeBuffer buf; 41 | std::thread readThread; 42 | std::promise stopRead; 43 | 44 | PIMP_DECLARE_PUBLIC (TerminalNotifier) 45 | }; 46 | } 47 | 48 | /* ========================================================================== */ 49 | #endif /* PIDUINO_TERMIONOTIFIER_PRIVATE_H defined */ 50 | -------------------------------------------------------------------------------- /utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright © 2018 Pascal JEAN, All rights reserved. 2 | # This file is part of the Piduino Project. 3 | # 4 | # The Piduino Project is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # The Piduino Project is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with the Piduino Project. If not, see . 16 | # piduino/utils CMakeLists.txt 17 | 18 | cmake_minimum_required(VERSION 3.0) 19 | 20 | # set packaging dir 21 | if(NOT CPACK_PACKAGE_DIRECTORY) 22 | set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages) 23 | endif() 24 | 25 | add_subdirectory (pido) 26 | add_subdirectory (pinfo) 27 | -------------------------------------------------------------------------------- /utils/pido/exception.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino pido tool. 3 | * Piduino pido tool is free software: you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * Piduino pido tool is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with Piduino pido tool. If not, see . 15 | */ 16 | #include 17 | #include 18 | #include "exception.h" 19 | 20 | // ----------------------------------------------------------------------------- 21 | Exception::Exception (Exception::Code code, int value) : 22 | _code (code), _value (value) { 23 | std::ostringstream s; 24 | 25 | switch (_code) { 26 | case CommandExpected: 27 | _msg.assign ("Command expected"); 28 | break; 29 | case ArgumentExpected: 30 | _msg.assign ("Arguments expected"); 31 | break; 32 | case BadArguments: 33 | _msg.assign ("Bad arguments"); 34 | break; 35 | case PinNumberExpected: 36 | _msg.assign ("Pin number expected"); 37 | break; 38 | case NotBinaryValue: 39 | s << _value << " is not a binary value"; 40 | _msg = s.str(); 41 | break; 42 | case NotPwmValue: 43 | s << _value << " is not a pwm value"; 44 | _msg = s.str(); 45 | break; 46 | case NotOutputPin: 47 | s << "Pin #" << value << " is not an output"; 48 | _msg = s.str(); 49 | case NotPwmPin: 50 | s << "Pin #" << value << " is not an pwm output"; 51 | _msg = s.str(); 52 | break; 53 | case PwmOpenError: 54 | s << "Unable to open pwm Pin #" << value; 55 | _msg = s.str(); 56 | break; 57 | case PwmWriteError: 58 | s << "Unable to write on pwm Pin #" << value; 59 | _msg = s.str(); 60 | break; 61 | default: 62 | break; 63 | } 64 | } 65 | 66 | 67 | Exception::Exception (Exception::Code code, const std::string& param) : 68 | _code (code), _param (param) { 69 | 70 | switch (_code) { 71 | case UnknownCommand: 72 | _msg.assign ("Invalid operation: "); 73 | break; 74 | case IllegalMode: 75 | _msg.assign ("Illegal mode: "); 76 | break; 77 | case BadPinNumber: 78 | _msg.assign ("Invalid pin number: "); 79 | break; 80 | default: 81 | break; 82 | } 83 | _msg.append (_param); 84 | } 85 | /* ========================================================================== */ 86 | -------------------------------------------------------------------------------- /utils/pido/exception.h: -------------------------------------------------------------------------------- 1 | /* Copyright © 2018 Pascal JEAN, All rights reserved. 2 | * This file is part of the Piduino pido tool. 3 | * Piduino pido tool is free software: you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * Piduino pido tool is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with Piduino pido tool. If not, see . 15 | */ 16 | #ifndef _PIDUINO_UTILS_PIDO_EXCEPTION_H_ 17 | #define _PIDUINO_UTILS_PIDO_EXCEPTION_H_ 18 | #include 19 | #include 20 | 21 | // ----------------------------------------------------------------------------- 22 | class Exception: public std::exception { 23 | public: 24 | enum Code { 25 | CommandExpected = 1, 26 | UnknownCommand, 27 | ArgumentExpected, 28 | BadArguments, 29 | IllegalMode, 30 | PinNumberExpected, 31 | BadPinNumber, 32 | NotBinaryValue, 33 | NotPwmValue, 34 | NotOutputPin, 35 | NotPwmPin, 36 | PwmOpenError, 37 | PwmWriteError 38 | }; 39 | 40 | explicit Exception (Exception::Code code, int value = 0); 41 | explicit Exception (Exception::Code code, const std::string& param); 42 | explicit Exception (Exception::Code code, const char* param) : Exception (code, std::string (param)) {} 43 | virtual ~Exception() throw () {} 44 | 45 | /** Returns a pointer to the (constant) error description. 46 | * @return A pointer to a const char*. The underlying memory 47 | * is in posession of the Exception object. Callers must 48 | * not attempt to free the memory. 49 | */ 50 | virtual const char * what() const throw () { 51 | 52 | return _msg.c_str(); 53 | } 54 | 55 | 56 | virtual Exception::Code code() const throw () { 57 | return _code; 58 | } 59 | 60 | protected: 61 | Exception::Code _code; 62 | std::string _param; 63 | int _value; 64 | std::string _msg; 65 | }; 66 | /* ========================================================================== */ 67 | #endif /*_PIDUINO_UTILS_PIDO_EXCEPTION_H_ defined */ 68 | -------------------------------------------------------------------------------- /utils/pido/pido.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /utils/piduino-utils.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /utils/pinfo/pinfo.workspace: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------